Showing posts with label CSS3. Show all posts
Showing posts with label CSS3. Show all posts

Thursday, November 12, 2020

Create React App: Get React Projects Ready Fast

Starting a new React project isn’t that simple. Instead of diving straight into code and bringing your application to life, you have to spend time configuring the right build tools to set up a local development environment, unit testing, and a production build. Luckily, help is at hand in the form of Create React App.

Create-React-App is a command-line tool from Facebook that allows you to generate a new React project and use a pre-configured webpack build for development. It has long since become an integral part of the React ecosystem that removes the need to maintain complex build pipelines in your project, letting you focus on the application itself.

How Does Create React App Work?

Create React App is a standalone tool that can be run using either npm or Yarn.

You can generate and run a new project using npm just with a couple of commands:

npx create-react-app new-app
cd new-app
npm start

If you prefer Yarn, you can do it like this:

yarn create react-app new-app
cd new app
yarn start

Create React App will set up the following project structure:

new-app
├── .gitignore
├── node_modules
├── package.json
├── public
│   ├── favicon.ico
│   ├── index.html
│   ├── logo192.png
│   ├── logo512.png
│   ├── manifest.json
│   └── robots.txt
├── README.md
├── src
│   ├── App.css
│   ├── App.js
│   ├── App.test.js
│   ├── index.css
│   ├── index.js
│   ├── logo.svg
│   ├── reportWebVitals.js
│   └── setupTests.js
└── yarn.lock

It will also add a react-scripts package to your project that will contain all of the configuration and build scripts. In other words, your project depends on react-scripts, not on create-react-app itself. Once the installation is complete, you can fire up the dev server and start working on your project.

Basic Features

Local Development Server

The first thing you’ll need is a local development environment. Running npm start will fire up a webpack development server with a watcher that will automatically reload the application once you change something. Starting from v4, Create React App supports React’s fast refresh as an alternative to Hot Module Replacement. Like its predecessor, this allows us to quickly refresh parts of the application after making changes in the codebase, but has some new features as well. Fast Reload will try to reload only the modified part of the application, preserve the state of functional components and hooks, and automatically reload the application after correcting a syntax error.

You can also serve your application over HTTPS, by setting the HTTPS variable to true before running the server.

The application will be generated with many features built in.

ES6 and ES7

The application comes with its own Babel preset — babel-preset-react-app — to support a set of ES6 and ES7 features. Some of the supported features are:

  • Async/await
  • Object Rest/Spread Properties
  • Dynamic import()
  • Class Fields and Static Properties

Note that Create React App does not provide any polyfills for runtime features, so if you need any of these, you need to include them yourself.

Asset Import

You can import CSS files, images, or fonts from your JavaScript modules that allow you to bundle files used in your application. Once the application is built, Create React App will copy these files into the build folder. Here’s an example of importing an image:

import image from './image.png';

console.log(image); // image will contain the public URL of the image

You can also use this feature in CSS:

.image {
  background-image: url(./image.png);
}

Styling

As mentioned in the previous section, Create React App allows you to add styles by just importing the required CSS files. When building the application, all of the CSS files will be concatenated into a single bundle and added to the build folder.

Create React App also supports CSS modules. By convention, files named as *.module.css are treated as CSS modules. This technique allows us to avoid conflicts of CSS selectors, since Create React App will create unique class selectors in the resulting CSS files.

Alternatively, if you prefer to use CSS preprocessors, you can import Sass .scss files. However, you’ll need to install the node-sass package separately.

Additionally, Create React App provides a way to add CSS Resets by adding @import-normalize; anywhere in your CSS files. Styles also undergo post-processing, which minifies them, adds vendor prefixes using Autoprefixer, and polyfills unsupported features, such as the all property, custom properties, and media query ranges.

Running Unit Tests

Executing npm test will run tests using Jest and start a watcher to re-run them whenever you change something:

 PASS  src/App.test.js
  ✓ renders learn react link (19 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.995 s
Ran all test suites.

Watch Usage
 › Press f to run only failed tests.
 › Press o to only run tests related to changed files.
 › Press q to quit watch mode.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press Enter to trigger a test run.

Jest is a test runner also developed by Facebook as an alternative to Mocha or Karma. It runs the tests in a Node environment instead of a real browser, but provides some of the browser-specific globals using jsdom.

Jest also comes integrated with your version control system and by default will only run tests on files changed since your last commit. For more on this, refer to “How to Test React Components Using Jest”.

ESLint

During development, your code will also be run through ESLint, a static code analyzer that will help you spot errors during development.

Continue reading Create React App: Get React Projects Ready Fast on SitePoint.


by Pavels Jelisejevs via SitePoint

Wednesday, November 11, 2020

How to Use Raygun to Identify and Diagnose Web Performance Problems

Web application development is difficult. There is no other type of application that is as involved, or requires you to understand multiple languages, frameworks, and platforms, as web applications. The most basic web application is comprised of two separate applications: 

  1. The server-side application to manage data.
  2. The client-side application displays that data to the user.

The simplest application is written in two languages—one for the server, and HTML for the client. But that's not all: modern applications require you to understand many languages, frameworks, and development tools. At best, an application is developed by multiple teams that can individually focus on smaller pieces of the larger whole. At worst, a team as small as one person develops the entire application.

But the story doesn’t end when an application is “finished”. After a lengthy and involved development processes, there are countless hours of testing for bugs, security issues, integration, performance, and user experience. Although many developers won't admit it, performance and the user experience are often overlooked. The result, of course, is that slow, unrefined applications are released into production.

That’s exactly why tools like Raygun’s Application Performance Monitoring (APM) and Real User Monitoring (RUM) exist. They provide developers the means to quickly analyze not only how your application performs in production, but it pinpoints the exact performance issues down to the method or database query, as well as visualizing your visitors’ experiences.

In this article, I will walk you through my experience using Raygun’s APM and RUM to pinpoint issues in a live, in-production website and the steps I took to fix them.

The Problem: A Legacy Application With a Complex Codebase

I work in a fast-paced environment where quantity is more important than quality. That’s not to suggest the software I or my co-workers write is subpar; our applications work well. But the demand on our time requires us to focus more on bugs and security than performance and the user experience.

I recently used Raygun’s APM and RUM to monitor our main public web application: an informational website for the company’s investors. It is written in C# and runs on the .NET 4.6.x runtime.

This application started as multiple small projects written by a team of three people with minimal communication. The projects shared a “core” library that quickly grew into a massive, unwieldy behemoth with a lot of duplicated functionality (as I said, there wasn’t a lot of communication). 

Over the years, the multiple projects morphed into a single large application. It pulls information from multiple MSSQL databases and an IBM DB2 machine to provide visitors with a wide array of economic and industry information. It interacts with other systems on the network, ranging from mail and file servers and other RESTful API services to perform other tasks.

I should also mention that I am somewhat unique in that I have a heavy IT background. My job title is “Programmer/Analyst”, but my actual duties consist of network and systems admin, programmer, and analyst. So when it comes to analyzing any issue, I'm equipped to examine both the code and the systems it runs on and interacts with.

Identifying Performance Issues

I know that my application has several performance issues; one of them is the authentication experience. Visitors must first authenticate using their credentials and then provide their OTP (one-time passcode) for two-factor authentication. Some visitors use a separate authenticator app on their mobile device to generate their OTPs, but most visitors receive their code via email. For the latter group, the authentication experience can take anywhere from 1 to 30 seconds, with most visitors experiencing longer waits.

After installing and configuring Raygun’s APM agent (a very simple process), I started seeing trace data in the dashboard within a minute. The dashboard gives you a glimpse of your application’s performance issues, providing tables and graphs showing the slowest requests, class methods, traces, SQL commands, and external API calls. Sure enough, some of the immediate offenders were related to the authentication process.

The top two slow URLs are used during the authentication process for visitors with emailed OTPs. Both are concerning (holy cow! 31 seconds for one request for /resend2fa). I certainly want to fix all the issues, but my time is limited. Therefore, fixing some of the issues with the /login endpoint is my priority.

Judging from the data provided by the “Slowest requests” table, I already suspect that the culprit is related to the process of sending emails. To be sure, I click the /login link to view the data that APM collected on that URL.

Analyzing the Data

APM collects a lot of information for every request, and it is extremely helpful because it can break down a request into its smaller parts—the methods that execute to provide the visitor with a response. The following screenshot shows the methods, ranked slowest to fastest, for the /login URL:

As expected, the main issue has something to do with the email process. It’s also interesting that the IBM DB2 ADO.NET provider is used during authentication. It shouldn’t be, and it's taking a rather significant amount of time to clear error info (as denoted by the call to IBM.Data.DB2.iSeries.MPConnection.clearErrorInfo()) that shouldn’t even be there. But that’s an issue for another day.

Apart from daily notifications, all emails sent by the website are dispatched on demand. The code that sends these emails is used in a variety of other applications that does not exhibit any performance issues. So in my mind, neither the code or the email server is at fault—there's something wrong on the machine that runs our public site.

There are so many things on a computer system that can cause performance issues. So, after viewing the logs and not seeing any apparent causes, I decide to spin up a new virtual machine and test the website on it. After installing the APM agent on the new machine and testing the login process, I notice a tremendous improvement.

The above screenshot shows the breakdown of where the application calls the SendMessage() method. Simply transferring the application to another machine cut the login process down by 26 seconds! While that's certainly a huge improvement, it still takes an average of 4-5 seconds for the initial login process.

Examining the flamechart for a single /login request (shown below), I can clearly see that sending an email is still an issue because SendMessage() still takes at least 3 seconds to completely execute. 

I can solve this problem by submitting the email message to a queue or batch, and let a separate process send the message. But that feels like a work-around to me. I'd rather find and fix the issue, but I also need to manage my time. There are other, arguably more important projects that I need to complete.

Analyzing the User Experience

Raygun's APM gives you clear performance data for your server, but that's only half of your application. What happens in the browser is just as important as what happens on the server, and Raygun's Real User Monitoring (RUM) gives you insight into how your users experience your application. Not only can it track your users' individual sessions and provide usage statistics (such as number of page visits, durations, and browsers), but it can also give you an accurate picture of their experience as they navigate from page to page.

RUM also displays each requested page and breaks down a its load time into different factors, as shown here:

The /cico URL in this screenshot has a rather high server time of 5 seconds, which is understandable because that page calculates a lot of data gathered from multiple sources on the fly. But now that I see that working with live data greatly slows down the page load, I need to implement a caching/summarizing solution. 

Notice that the /takepay URL has a rather small server time (it works with cached/summarized data), but it has a large render time due to rendering interactive graphs with many data points. So, I can easily solve the slow server response for /cico by daily caching or summarizing the data it works with in a separate process.

But there's more to performance and a user's experience than just response times; when properly configured, RUM catalogs all requests—including XHR, as shown below:

The first thing that caught my eye were the 30+ requests for the /settings/email-alerts URL. Either 30+ people viewed/changed their email alert settings, or that XHR is automatically executed on one of the pages. Unfortunately, RUM didn't give me an immediate idea of what page made the XHR, but I did eventually find the culprits when viewing the performance reports for various pages:

Those needless XHRs do contribute to the load time, and eliminating them can make a big difference..

Conclusion

Raygun provides an invaluable service. As my experience shows, by using APM and Real User Monitoring, you can easily monitor your application's performance. 

They automatically pinpoint the performance issues on both the server and client, which is vital in a fast-paced environment. They truly are fantastic services and you can try them free today!


by Jeremy McPeak via Envato Tuts+ Code

Monday, November 9, 2020

Getting Started with React Native

Getting Started with React Native

With the ever-increasing popularity of smartphones, developers are looking into solutions for building mobile applications. For developers with a web background, frameworks such as Cordova and Ionic, React Native, NativeScript, and Flutter allow us to create mobile apps with languages we’re already familiar with: HTML, XML, CSS, and JavaScript.

In this guide, we’ll take a closer look at React Native. You’ll learn the absolute basics of getting started with it. Specifically, we’ll cover the following:

  • what React Native is
  • what Expo is
  • how to set up an React Native development environment using Expo
  • how to create an app with React Native

Prerequisites

This tutorial assumes that you’re coming from a web development background. The minimum requirement for you to be able to confidently follow this tutorial is to know HTML, CSS, and JavaScript. You should also know how to install software on your operating system and work with the command line. We’ll also be using some ES6 syntax, so it would help if you know basic ES6 syntax as well. Knowledge of React is helpful but not required.

What is React Native?

React Native is a framework for building apps that work on both Android and iOS. It allows you to create real native apps using JavaScript and React. This differs from frameworks like Cordova, where you use HTML to build the UI, which will then just be displayed within the device’s integrated mobile browser (WebView). React Native has built-in components which are compiled to native UI components, while your JavaScript code is executed through a virtual machine. This makes React Native more performant than Cordova.

Another advantage of React Native is its ability to access native device features. There are many plugins which you can use to access native device features, such as the camera and various device sensors. If you’re in need of a platform-specific feature that hasn’t been implemented yet, you can also build your own native modules — although that will require you to have considerable knowledge of the native platform you want to support (Java or Kotlin for Android, and Objective C or Swift for iOS).

If you’re coming here and you’re new to React, you might be wondering what it is. React is a JavaScript library for the Web for building user interfaces. If you’re familiar with MVC, it’s basically the View in MVC. React’s main purpose is to allow developers to build reusable UI components. Examples of these components include buttons, sliders, and cards. React Native took the idea of building reusable UI components and brought it into mobile app development.

What is Expo?

Before coming here, you might have heard of Expo. It’s even mentioned in the official React Native docs, so you might be wondering what it is.

In simple terms, Expo allows you to build React Native apps without the initial headache that comes with setting up your development environment. It only requires you to have Node installed on your machine, and the Expo client app on your device or emulator.

But that’s just how Expo is initially sold. In reality, it’s much more than that. Expo is actually a platform that gives you access to tools, libraries and services for building Android and iOS apps faster with React Native. Expo comes with an SDK which includes most of the APIs you can ask for in a mobile app development platform:

Those are just few of the APIs you get access to out of the box if you start building React Native apps with Expo. Of course, these APIs are available to you as well via native modules if you develop your app using the standard React Native setup.

Plain React Native or Expo?

The real question is which one to pick — plain React Native or Expo? There’s really no right or wrong answer. It all depends on the context and what your needs are. But I guess it’s safe to assume that you’re reading this tutorial because you want to quickly get started with React Native. So I’ll go ahead and recommend that you start out with Expo. It’s fast, simple, and easy to set up. You can dive right into tinkering with React Native code and get a feel of what it has to offer in just a couple of hours.

But as you begin to grasp the different concepts, and as the need for different native features arises, you might find that Expo is kind of limiting. Yes, it has a lot of native features available, but not all the native modules that are available to standard React Native projects are supported.

Note: projects like unimodules are beginning to close the gap between standard React Native projects and Expo projects, as it allows developers to create native modules that work for both React Native and ExpoKit.

Setting Up the React Native Development Environment

To quickly get started with React Native, the recommended method is to set up Expo.

The only prerequisite of setting up Expo is that you need to have Node.js installed in your machine. To do this, you can either head to the official Node download page and grab the relevant binaries for your system, or you can use a version manager, which allows you to install multiple versions of Node and switch between them at will.

Once you have Node.js installed, install the Expo CLI. This is used for creating, serving, packaging, and publishing projects:

npm install -g expo-cli

Next, install Yarn, the preferred package manager for Expo:

npm install -g yarn

That’s really all there is to it! The next step is to download the Expo client App for Android or iOS. Note that this is the only way you can run Expo apps while you’re still in development. When you’re ready to ship the app, you can follow this guide to create standalone binaries for iOS and Android which can be submitted to the Apple App Store and Google Play Store.

What We’ll Be Building

Now that your development environment is set up, we can look at the app we’re going to create — a Pokémon search app. It will allow the user to type the name of a Pokémon into an input box, before fetching the Pokémon’s details from an external API and displaying them to the user.

Here’s what the finished thing will look like:

Pokémon Search App

As ever, you can find the source code for this in our GitHub repo.

Bootstrapping the App

On your terminal, execute the following command to create a new React Native project using Expo:

expo init RNPokeSearch

Under Managed Workflow, select blank. By default, this will install the dependencies using Yarn.

expo init

You might be asking what this Managed workflow and Bare workflow is. These are the two types of workflows that Expo supports. With a managed workflow, you only have to deal with JavaScript and Expo manages everything for you. While in Bare workflow, you have full control over the native code. It gives you the same freedom as the React Native CLI, but with the added bonus of Expo’s libraries and services. You can visit this managed vs bare intro page if you want to learn more about workflows in Expo.

Just like in a web environment, you can install libraries to easily implement different kinds of functionality in React Native. Once the project is created, we need to install a couple of dependencies: pokemon and axios. The former is used for verifying if the text entered in the search box is a real Pokémon name, while axios is used to make an HTTP request to the API that we’re using, namely the PokeAPI:

yarn add pokemon axios

React Native Project Directory Structure

Before we proceed to coding, let’s first take a look at the directory structure of a React Native project created with Expo:

Expo project directory

Here’s a breakdown of the most important files and folders that you need to remember:

  • App.js: the main project file. This is where you’ll start developing your app. Any changes you make to this file will be reflected on the screen.
  • src: acts as the main folder which stores all the source code related to the app itself. Note that this isn’t included in the default project created by Expo CLI. The name of this folder can be anything. Some people use app as well.
  • assets: this is where the app assets such as icons and splash screens are stored.
  • package.json: where the name and versions of the libraries you installed for this project are added.
  • node_modules: where the libraries you installed are stored. Note that this already contains a lot of folders before you installed the two libraries earlier. This is because React Native also has its own dependencies. The same is true for all the other libraries you install.

Don’t mind the rest of the folders and files for now, as we won’t be needing them when just getting started.

Running the App

At this point, you can now run the app by executing the command below. Make sure that you’ve already installed the corresponding Expo client (Android or iOS) for your phone and that it’s connected to the same network as your computer before doing so. If you don’t have an Android or iOS device you can test with, you can use the Android Studio Emulator or the iOS simulator so you can run the app on your machine:

yarn start

Once it’s running, it will display a QR code:

Expo yarn start

Open your Expo client app, and in the projects tab click on Scan QR Code. This will open the app on your Android or iOS device. If you have an emulator running, you can either press i to run it on the iOS simulator or a to run it on the Android emulator.

Expo client app

If you’re testing on a real device, shake it so the developer menu will show up.

React Native developer settings

Make sure that Fast Refresh is enabled. This allows you to automatically reload the changes that you make on your components.

Continue reading Getting Started with React Native on SitePoint.


by Wern Ancheta via SitePoint

Thursday, November 5, 2020

How to Find & Fix Common Website Accessibility Issues

It’s the 2020s, so we shouldn’t any longer have to make the case for accessibility. An accessible site means you reach more people, the people you reach (even abled ones) all have an easier time using your site, and you won’t get sued. And with the tools and resources available to developers and designers, it’s now easier than ever to make sure you have an accessible site.

At Polypane, accessibility is one of the three core areas we focus on, the other two being performance and responsive design. If you’re not familiar with Polypane, it’s a web browser specifically for web developers. It has all sorts of tools you won’t find in regular browsers — tools that make you more effective and efficient. To learn more about Polypane, check out the introduction article.

In this article, we’ll focus on a few common accessibility issues and find ways to audit and fix them in your site to make sure it’s as accessible as possible. Here’s what we’ll look at:

  • Does my text have enough contrast, and where it doesn’t, how do I fix that?
  • How does my site look for people with visual impairments like color blindness or farsightedness? What about situational impairments like bright sunlight or a device with night mode?
  • Does my page structure make sense for people that depend on it?
  • How do I make sure I don’t have any code quality issues in my site, and are the things I did to improve accessibility actually helping?
  • Does my site work well on smaller screens?
  • How do I make sure my site works well for users that prefer dark colors or don’t deal well with motion?

Contrast

Does my text have enough contrast, and where it doesn’t, how do I fix that?

Ideally, text contrast is dealt with during the design, with tools like Stark making it easy to test individual text and background pairs. But unfortunately, this isn’t always the case. While there are plenty of places online to check a given text color and a given background (we even built our own online color contrast tester), your web pages likely have many different colors and backgrounds, and for any reasonably complex site, you might not know all combinations beforehand.

And that makes it really easy to overlook that one grey text that’s normally shown on a white background, but has this one place where it’s on light gray, or a dark text color with opacity that only works for certain backgrounds.

In Polypane, nearly all interactions with an element will do a quick contrast check for that specific element. Our algorithm determines the real text and background colors, taking into account the color, opacity and all background colors. We then merge that into the actual perceived text and background color and compare that.

comparing text and background color

We’ll show the result in an element tooltip and in the elements panel alongside other information like font family and font size. That way, your text contrast is always glanceable.

That still relies on chance, though, so Polypane also has a color contrast overlay. This will go through your entire page and find all unique text and background combinations, check all of them and add labels to each element. All passing contrast pairs get a single label with the contrast, and any failing contrast gets a warning label for each instance, so you don’t overlook any.

passing and warning labels on a website

We made it really easy to find contrast issues. But how do you fix them?

If you’re lucky, you can use another color from your design system, but if you don’t have one, or if this is a one-off color pair, you have to go back to your designer or use an online contrast tester and find another color yourself — a tedious and time-consuming process, and something I wanted to do something about.

A GIF showing that valid color options appear as you hover over a warning label

For every failing contrast pair, Polypane calculates a text color that has enough contrast with the background, and suggests that to you for easy copying. You can even preview it just by hovering over it. (The online contrast checker we mentioned also suggests improved colors for you.)

Visual and Situational Impairments

How does my site look for people with visual impairments like color blindness or farsightedness? What about situational impairments like bright sunlight or a device with night mode?

Not everyone that visits your site is going to have perfect vision. In fact, a large number of your visitors will definitely have some form of visual impairment. And while you can make sure to follow guidelines around minimum text size and not communicate anything just through use of colors, it can be easy to overlook an issue. The best way to get empathy is to try to simulate how other people experience your site.

A visual showing multiple test results for a page based on impairment

Color blindness

Between 8 and 10% of men worldwide are color blind (women much less so, at 0.5%), and they fall in three different groups: red-green color blindness, blue-yellow color blindness, and full color blindness. Polypane lets you simulate all of these with our accessibility overlays.

You should test with these simulators to make sure that you don’t rely on just color to bring across messages. For example, if you just make the border of an input field red when you make an error, you’ll find that’s barely noticeable, or unnoticeable with any of these simulators turned on. Rather, you should provide a second, non-color indicator like an error message to communicate the issue to your user.

Red-green color blindness is the most common and the vast majority of people with color blindness have this. In Polypane, we offer four different simulators: Deuteranopia, Deuteranomaly, Protanopia and Protanomaly. The -anomaly variants here are the less severe version, while the -opia variants would be classified as “full” red-green color blindness.

As the name implies, people with this type of color blindness have difficulty seeing the difference between red and green, but also brown and orange and certain shades of blue and purple. You can see how, for example, the common “green is good, red is bad” coloring of elements can become an issue.

Blue-yellow color blindness is much more rare, at just 0.0002% of men worldwide. The technical name for it is “tritanopia”, and tritanomaly is the less severe version. This type of color blindness makes people less sensitive to blue light, making the blue part of anything grey.

Lastly, full colorblindness is the most rare at 0.00003% of men worldwide. Its proper name is “Achromatopsia”, with “achromatomaly” being the less severe version where people see some color, but it’s severely dulled.

It’s worth noting that the simulators in Polypane (and any simulator really) are approximations. Especially the less severe variants come in a range from nearly unnoticeable to close to the full thing, and so the simulator chooses a middle ground there.

various states of the SitePoint home page

Continue reading How to Find & Fix Common Website Accessibility Issues on SitePoint.


by Kilian Valkhof via SitePoint

Monday, November 2, 2020

How to Organize a Large React Application and Make It Scale

An astronaut constructing a space colony in the shape of the React logo

This article is by guest author Jack Franklin. SitePoint guest posts aim to bring you engaging content from prominent writers and speakers of the Web community.

In this article, I’ll discuss the approach I take when building and structuring large React applications. One of the best features of React is how it gets out of your way and is anything but descriptive when it comes to file structure. Therefore, you’ll find a lot of questions on Stack Overflow and similar sites asking how to structure applications. This is a very opinionated topic, and there’s no one right way. In this article, I’ll talk you through the decisions I make when building React applications: picking tools, structuring files, and breaking components up into smaller pieces.

An astronaut constructing a space colony in the shape of the React logo

Build Tools and Linting

It will be no surprise to some of you that I’m a huge fan of webpack for building my projects. Whilst it’s a complicated tool, the great work put into version 5 by the team and the new documentation site make it much easier. Once you get into webpack and have the concepts in your head, you really have incredible power to harness. I use Babel to compile my code, including React-specific transforms like JSX, and the webpack-dev-server to serve my site locally. I’ve not personally found that hot reloading gives me that much benefit, so I’m more than happy with webpack-dev-server and its automatic refreshing of the page.

I use ES Modules, first introduced in ES2015 (which is transpiled through Babel) to import and export dependencies. This syntax has been around for a while now, and although webpack can support CommonJS (aka, Node-style imports), it makes sense to me to start using the latest and greatest. Additionally, webpack can remove dead code from bundles using ES2015 modules which, whilst not perfect, is a very handy feature to have, and one that will become more beneficial as the community moves towards publishing code to npm in ES2015. The majority of the web ecosystem has moved towards ES Modules, so this is an obvious choice for each new project I start. It’s also what most tools expect to support, including other bundlers like Rollup, if you’d rather not use webpack.

Folder Structure

There’s no one correct folder structure for all React applications. (As with the rest of this article, you should alter it for your preferences.) But the following is what’s worked well for me.

Code lives in src

To keep things organized, I’ll place all application code in a folder called src. This contains only code that ends up in your final bundle, and nothing more. This is useful because you can tell Babel (or any other tool that acts on your app code) to just look in one directory and make sure it doesn’t process any code it doesn’t need to. Other code, such as webpack config files, lives in a suitably named folder. For example, my top-level folder structure often contains:

- src => app code here
- webpack => webpack configs
- scripts => any build scripts
- tests => any test specific code (API mocks, etc.)

Typically, the only files that will be at the top level are index.html, package.json, and any dotfiles, such as .babelrc. Some prefer to include Babel configuration in package.json, but I find those files can get large on bigger projects with many dependencies, so I like to use .eslintrc, .babelrc, and so on.

React Components

Once you’ve got a src folder, the tricky bit is deciding how to structure your components. In the past, I’d put all components in one large folder, such as src/components, but I’ve found that on larger projects this gets overwhelming very quickly.

A common trend is to have folders for “smart” and “dumb” components (also known as “container” and “presentational” components), but personally I’ve never found explicit folders work for me. Whilst I do have components that loosely categorize into “smart” and “dumb” (I’ll talk more on that below), I don’t have specific folders for each of them.

We’ve grouped components based on the areas of the application where they’re used, along with a core folder for common components that are used throughout (buttons, headers, footers — components that are generic and very reusable). The rest of the folders map to a specific area of the application. For example, we have a folder called cart that contains all components relating to the shopping cart view, and a folder called listings that contains code for listing things users can buy on a page.

Categorizing into folders also means you can avoid prefixing components with the area of the app they’re used for. As an example, if we had a component that renders the user’s cart total cost, rather than call it CartTotal I might prefer to use Total, because I’m importing it from the cart folder:

import Total from '../cart/total'
// vs
import CartTotal from '../cart/cart-total'

This is a rule I find myself breaking sometimes. The extra prefix can clarify, particularly if you have two to three similarly named components, but often this technique can avoid extra repetition of names.

Prefer the jsx Extension over Capital Letters

A lot of people name React components with a capital letter in the file, to distinguish them from regular JavaScript files. So in the above imports, the files would be CartTotal.js, or Total.js. I tend to prefer to stick to lowercase files with dashes as separators, so in order to distinguish I use the .jsx extension for React components. Therefore, I’d stick with cart-total.jsx.

This has the small added benefit of being able to easily search through just your React files by limiting your search to files with .jsx, and you can even apply specific webpack plugins to these files if you need to.

Whichever naming convention you pick, the important thing is that you stick to it. Having a combination of conventions across your codebase will quickly become a nightmare as it grows and you have to navigate it. You can enforce this .jsx convention using a rule from eslint-plugin-react.

One React Component per File

Following on from the previous rule, we stick to a convention of one React component file, and the component should always be the default export.

Normally our React files look like so:

import React from 'react'

export default function Total(props) {
  …
}

In the case that we have to wrap the component in order to connect it to a Redux data store, for example, the fully wrapped component becomes the default export:

import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'

export default function Total(props) {
  …
}

export default connect(() => {…})(Total)

You’ll notice that we still export the original component. This is really useful for testing, where you can work with the “plain” component and not have to set up Redux in your unit tests.

By keeping the component as the default export, it’s easy to import the component and know how to get at it, rather than having to look up the exact name. One downside to this approach is that the person importing can call the component anything they like. Once again, we’ve got a convention for this: the import should be named after the file. So if you’re importing total.jsx, the component should be imported as Total. user-header.jsx becomes UserHeader, and so on.

It’s worth noting that the one component per file rule isn’t always followed. If you end up building a small component to help you render part of your data, and it’s only going to be used in one place, it’s often easier to leave it in the same file as the component that uses it. There’s a cost to keeping components in separate files: there are more files, more imports and generally more to follow as a developer, so consider if it’s worth it. Like most of the suggestions in this article, they are rules with exceptions.

Continue reading How to Organize a Large React Application and Make It Scale on SitePoint.


by Jack Franklin via SitePoint

Friday, October 30, 2020

23+ Best iOS App Templates of 2020

Building an app used to be the domain of hardcore developers only, but with over 2,500 iOS app templates for sale at CodeCanyon, even complete beginners to coding can build an app. That's because an app template gives you the complete source code to a working iPhone app, with key functions already implemented. Just add features to create the product you want!

Many beginners use app templates as a learning tool to improve their coding skills, while others choose to upload their new app creations to iTunes for approval and inclusion in the app store.

CiyaShop eCommerce iOS Template
CiyaShop is one of the many high-quality iOS mobile app templates available on CodeCanyon.

Integrating an app template into the development process will allow you to start with a professionally designed template, so you can quickly launch your app. Having a template reduces your costs for development and cuts down on bugs. Save time and money by using a premium iOS app template from CodeCanyon.

The Best iPhone and iOS App Templates on CodeCanyon

CodeCanyon has a library of some of the best iOS app templates ever created. With a low-cost, one-time payment, you can purchase these high-quality iOS mobile app templates and bootstrap your iPhone or iOS app project. 

Here are some of the weekly best-selling iOS mobile app templates available on CodeCanyon for 2020.

Best-Selling iOS App Templates Available on CodeCanyon

These feature-rich iOS app templates will help you focus on running your business rather than designing an app. With the premium apps offered on CodeCanyon, you will be able to create all types of apps in many different industries, such as:

  • cryptocurrency
  • fashion
  • ride-sharing
  • restaurant
  • eCommerce

Head on over to CodeCanyon and find the right iOS app template now!

Top 20 iOS App Templates (From CodeCanyon for 2020)

1. Best-Seller: Universal for iOS

Universal iOS App Layout Template

The magic of the Universal for iOS app layout template is that it lets users create just about any app they want by pulling in unlimited content from blogs, timelines, feeds, channels, playlists, or webpages, and easily combining them in one customisable app.

One of the best-selling iOS mobile app templates at CodeCanyon, Universal for iOS supports most popular web resources, like WordPress, YouTube, Facebook, RSS, etc. It also supports AdMob and gives your users the option of removing banners and interstitial ads with an easy in-app purchase.

The iOS starter app is completely based on Objective-C and designed for the latest version of iOS. It comes with step-by-step instructions and video tutorials on how to configure your template from scratch, and it's suitable for both professionals and beginners as no code knowledge is required.

User thesanguy says:

"Universal for iOS offers an extremely flexible code base for a wide variety of app designs. I found the documentation and support to be top notch, and I am a complete novice with Xcode. My app was quickly approved by Apple and I was very pleased with the end result."

2. Best-Seller: WebViewGold

WebViewGold Apple App Template

The WebViewGold Apple app template is another great iOS template that allows users to convert website content into an app. It does so by using a Swift Xcode package to wrap the URL or local HTML into an iOS app. The real genius of this HTML5 iOS app template, though, is that it does its work in just a few clicks. So no coding knowledge is required! WebViewGold is optimised for iPhone, iPod Touch, and iPad.

Apps made with this iPhone web design template are 100% guaranteed by the author to get acceptance into the Apple App Store.

Try this out if you've been looking for template apps for iPad and iPhone. User talimagnum says:

“I have been using this code for a while now and I have to tell it has been awesome. I have never had any trouble and the only time I needed help they answered really fast.”

3. Best-Rated: CiyaShop Native iOS Application

CiyaShop Native iOS Application iOS App Layout Template

Need to create an app quickly and easily that is compatible with WooCommerce themes? Look no further! The CiyaShop iOS starter app is an ideal solution for your eCommerce business. If you are a retail store, marketplace, or fashion shop looking to buy iOS app code, then this is the right app template for you. 

Here's what you can expect from this eCommerce iOS template:

  • WooCommerce theme synchronization
  • reward points
  • multi-vendor support
  • push notifications
  • delivery tracking

View the live preview of this iPhone and iPad app design template to see if it's the right fit for your business!

4. WooBox: WooCommerce iOS App

WooBox eCommerce iOS Template

The ideal app for shoppers, the WooBox app template helps developers create their own beautiful eCommerce app for mobile shoppers. WooBox includes more than 40 professionally designed screens to feature products. Other great features of this eCommerce iOS template include:

  • light and dark mode themes
  • RTL support for Arabic and Hebrew
  • Admob integration
  • wish list functionality
  • and more!

If you need to buy template apps for iPad and iPhone for eCommerce, then WooBox is what you've been looking for.

5. WoWonder IOS Messenger

WoWonder IOS Messenger iPhone App Template

WoWonder IOS Messenger is an iOS chat application template that allows end users to chat together on their mobile phones via the app or send and receive messages. The iOS template features:

  • registration page
  • ability to upload and share images as well as voice recordings
  • offline access to all messages and recent conversions
  • ability to control privacy and profile settings 

You can't go wrong with WoWonder if you've been looking to buy Xcode templates. User darkpixel66 says this about the iPhone app template:

"Great support and communication."

6. Store Finder Full iOS Application

Store Finder v19 Buy iOS App Code

When you need to find a specific item or store, and don’t want to spend all day driving from one end of town to the other or doing laps around the mall, a store finder app is a lifesaver. 

Enter the Store Finder iPhone app template, a developer’s dream, with a long list of must-have features like:

  • call, email, and SMS integration
  • Google directions
  • social media logins
  • pinch and zoom navigation
  • and so much more!

7. Web2App for IOS

Web2App for IOS iPhone Web Design Template

Web2App for IOS offers you another way to convert your website into a real iOS app. This HTML5 iOS app template offers great features like:

  • tabs
  • built-in advertisements
  • notifications
  • easy customisation
  • styling options

This iPhone app HTML5 template is highly customisable and ships with comprehensive documentation, video tutorials, and step-by-step instructions that make it easy to get started. You can choose from countless display modes and colors to suit your requirements, and of course customise the AdMob integration.

User misterzenith says this about the Web2App iPhone web design template:

“Design quality is awesome with well-commented code.”

8. Item Finder MarketPlace

Item Finder MarketPlace eCommerce iOS Template

The item finder marketplace allows you to easily set up an eCommerce marketplace with all the necessary features such as reviews, social media sharing, promotions, and detailed product descriptions. Other notable features for this eCommerce iOS template include SMS integration, user profiles, image sliders, and social logins. 

If you need to buy Xcode templates for your eCommerce marketplace, this template is perfect. See what this app is capable of by viewing the video preview.

9. Classify

Classify iPhone Application Template

Classify is an all-in-one iOS app template for ads. The iPhone application template allows you to create mobile classified services for professionals. The Apple app template is easy to customize to create just the look you need. 

Here are a few notable features for this iPhone app template:

  • AdMob interstitials
  • login and sign-up controllers
  • no external CMS needed
  • PSD graphics included

Here's what users are saying about this iOS template:

"The developer has created an amazing product that is easy to customize and has fast and accurate customer support." — arudkosky

Download this powerful iPhone app template now!

10. PikLab

PikLab iOS App Layout Template

The PikLab photo editor Apple app template was inspired by the popular AppStore app, PicLab. This iPhone application template has all the important features of modern photo editors. This makes editing images quick and easy for all users of the app. 

Here are a few of the iOS app layout template's most essential features:

  • text collages
  • sticker creation
  • filter, contrast, and texture photo editing
  • background insertion
  • PSD icon files included 

If you're looking to create a professional photo editing app, then this is the iPhone app template for you.

11. Events—iOS Universal Events App Template

Events iPhone App Template

Events is an iPhone app template created with Swift that allows developers to create their own mobile iOS events app to store and share events happening all over the world. End users are able to submit new events that you can approve and add to your Parse Dashboard. 

The iPhone app template also has a button that enables end users to automatically add an event on their native iOS Calendar and to open the address in Maps to get directions. They can also share the event via their social media platform of choice.

User dnederlof says this about the iPhone app template code:

"Great code and some of best support I've seen!"

12. PIXL

PIXL Buy iOS App Code

PIXL is an app template that comes with a built-in custom image editor for editing images and icons. It also comes with a customizable camera built with the AVFoundation framework. The iOS template allows you to either edit photos from your existing photo library or take pictures with your phone's camera. They're useful features if you've wanted to buy iOS app code for photography.

Here is what users of this iPhone app template are saying:

"Outstanding template and customer support! I highly recommend this app template!"—VL

13. Restaurant Food Delivery and Ordering System

Restaurant Food Delivery Ordering System iOS App Layout Template

This eCommerce iOS template is ideal for any on-demand delivery business or food delivery app like UberEats or Postmates. The process within the app allows your customers to create an account, choose a restaurant of their choice, select the food from this restaurant, and check out with cash or credit. 

Here are a few notable features of this eCommerce iPhone app template:

  • social login
  • phone verification
  • restaurant menu screens
  • seamless checkout
  • order tracking

14. Woopy

Woopy iOS Template

The Woopy iPhone and iPad application design template allows developers to create listing apps that facilitate buying and selling items online. Users can browse by keyword or category. They can also chat with sellers or potential buyers and give feedback on each transaction.

One of the Apple app template’s outstanding features for sellers is the ability to add a ten-second video to their listings. Another is the app’s optional email verification system that gives buyers and sellers extra assurance by posting a verification symbol next to the user’s name.

Customer Kaya09 said this about the iOS template: 

“Great support, well-designed app, and code is perfect. No issue with iTunes, approved in a few hours.”

15. SuperView

SuperView iPhone and iPad Application Design Template

SuperView is another great iPhone and iPad application design template created to enable users to easily create a native iOS container for their website. It is ideal for a single-page web app with on-screen or no navigation. Users who want to ease the difficult learning curve associated with the Swift programming language and iOS SDK will really appreciate SuperView.

This iOS app layout template also has some great features you can take advantage of in your app, including:

  • Firebase or OneSignal push notifications
  • GPS support
  • social network login
  • Google AdMob
  • support for right-to-left (RTL) languages such as Arabic

User muhsin2905 has this to say about the iPhone and iPad application design template:

"Really good app and really good support. No problem to release to app store. App is online and we are happy. I would buy this App again if I needed it."

16. Instagram Mobile Template

Instagram Mobile iPhone App Template Design

Love Instagram? Want to create your own Instagram-type app? We have just the thing for you. The Instagram Mobile Template is an iOS template that allows developers to create a photo and video sharing app in the vein of Instagram where users can follow, like, comment, and share photos. 

The Apple app template allows users to log in with their email, Google, or Facebook accounts and supports monetisation with AdMob. It also supports push notifications and comes with built-in analytics to monitor performance.

User Mbosoft says:

“Customer support, code quality, customizability. I recommend it to everyone. Always new, updated and easy to use. No need for coding knowledge. Just follow the steps."

17. Ads listing, Classified app for iOS

Ads Listing iPhone App Template Design

If you're looking to buy iOS app code to start a classifieds app, here's your top choice. By purchasing this iPhone app template code, you can set up in app purchases, multiple ad screens, different color themes, and a lot more. 

Features of this iPhone app template design include:

  • multiple currencies
  • Google AdMob
  • account profiles

19. FireApp Chat IOS (Inspired by WhatsApp)

Need to create a messaging app? This iPhone app template design will help you build a WhatsApp-style app in no time. The iOS starter app will allow users to easily communicate with their friends through messages and video calls. Users can share images, video, audio, stickers, location, and contacts when you set up the FireApp iOS template. 

20. ExpensesApp

ExpensesApp

We end our list of professional iOS app design templates with ExpensesApp. This is a great iPhone app template design that lets users manage their income and budgets. ExpensesApp uses a minimal layout that's easy for users to navigate. It comes with step by step documentation for easy setup, and it's 100 percent ready for the AppStore. If you've been looking for Apple template apps that can help people manage their money, try out ExpensesApp.

5 Free iOS App Design Templates to Download in 2020

The premium iOS mobile app templates available on CodeCanyon will undoubtedly give you the most advanced features and the best possible user experience. They are complete apps with full source code—in many cases you can customize them to create your own working app, without any coding. However, if you're on a tight budget, you might not want to use a paid template. The good news is that there are iPhone app template free download alternatives to the premium Apple template apps found above.

Many iOS app design templates or UI kits have been created by designers and are free to download and use in your own project. To create an app from one of these free app design templates, you will need to do all the coding yourself, though. The UI kit or design template will only include the layout and graphics for your app—you'll have to figure out how to turn this design into a real app. 

Below are my picks for the five best free iOS app design templates available on the web.

1. Move

Move iPhone App Template Free Download

The Move iPhone and iPad app template is free and will give you a clean and simple design that users can easily navigate. It comes with 12 different templates that will work for businesses and startups of all different types. 

2. Payment App UI Kit

If you need to accept payments on your app, then this free iOS app template UI kit features 11 different screens that will help your users send and receive money from contacts or people nearby. A few of the included screens in this kit are expense log, security login, contact chat, and manage money screens. Try this out if you need an iPhone and iPad app template that's free .

3. Amazon Refresh Design Sketch Resource

Amazon Refresh Design Sketch Resource iPhone App Design Template Free Download

This UI kit builds on the Amazon Marketplace UI and gives it a more modern feel. The iPhone app template free download kit comes with three screens that will help your business look professional. This iOS app design will make a great accompaniment to your online store app.

4. Restaurant Wireframe

If you're running any type of restaurant, fast food place, or food delivery service, this wireframe can be adapted to your needs. It's minimal design looks great and is hard to find in other iOS app design templates that are free online. The wireframe features two screens for searching specific types of foods and locations of the different eateries. If you've been looking for a restaurant iOS app design templates for free online, try out this wireframe.

5. Book App Concept

This iPhone app design template free download features a sleek and modern design that can not only work for books but for magazines as well. You can scroll and search through different books and magazines quickly and efficiently with this iPhone and iPad app template that's free. 

Explore More Great iOS App Templates for 2020

While the iOS mobile app templates mentioned above are some of the best available for 2020, they may not fit your business's needs. 

If none of the templates mentioned work for your current business or you need even more templates, then check out our other articles that contain plenty more ideas for high-quality premium and free iOS app templates:

So what are you waiting for? Get started on your new app today!


by Daniel Strongin via Envato Tuts+ Code