Views

Views are the main screens in your application and are comprised of various components.

Gravity comes with pre-built views for you to use in your app, including:

  • Auth views (sign up, sign in, reset password)

  • Account views (profile, password, users)

  • x2 dashboard templates

Views are located in the /views directory

Creating a New View

There is a template.js file inside the views directory that you can use to speed up the process of creating new views.

Your components within a view should always be wrapped inside a <ViewContainer> which will provide common components such as header, navigation and banner notifications.

Routing the View

Once you've built your view, you need to import it into /router.js and add it to a navigation stack.

Private Views

You can restrict access to a view to a specific user permission level. For example: only account admins can access the edit users view.

Inside the router – each view has an initialParams object where you can add the user permission level, for example, in the <AccountTabs/> stack:

<BottomTab.Screen name='users' component={ Users }
initialParams={{ private: true, permission: 'admin' }}/>

You should also consider conditionally rendering stack objects to only show links to views the user has permission for.

Last updated