Concepts
Annotation
Since MetaFox comes with Modular structure, Build tool helps solve issues of dependencies without using import directly. Build tool will scan all packages declared in settings.json file, find all components, librarys to build the bundle.
For example:
/**
* @type: route
* name: blog.blog.show
* path: blog/:id(\d+), blog/:id(\d+)/:slug
*/Best practices
- Keep anotation at the begin of source file
- Each file should declare only one component.
Annotation
| Type | Group |
|---|---|
| ui | UI components |
| route | screen route |
| saga | saga functions |
| siteDock | global components |
| reducer | reducer functions |
| service | services provider |
| middleware | middleware components |
| polyfills | polyfills |
ui
Shared UI component.
Example
/**
* @type: ui
* name: ui.NotificationSettings
*/Properties
name: Alias of the component.
-
Name rules
Syntax Prefix Description Example ui. ComponentNameui. UI component. ui.ViewMoreui.HeaderItemDetailsmarty. ComponentNamesmarty. List component. smarty.SmartResourceListsmarty.SmartTabsitem. module_name.resource_nameitem. Item component belongs to module_name,resource_name.item.event.event_memberitem. module_name.resource_name.ComponentNameitem. Special item component belongs to module_name,resource_name.item.event.event_member.EventHostembed. module_name.resource_nameembed. Embed component belongs to module_name,resource_name.embed.event.eventskeleton. module_name.resource_nameskeleton. Skeleton component belongs to module_name,resource_name.skeleton.event.eventskeleton. module_name.resource_name.ComponentNameskeleton. Special skeleton component belongs to module_name,resource_name.skeleton.event.event.EventHostform.element. ComponentNameform.element. Form component. form.element.Checkbox
Usage
Use name to get React component.
const { jsxBackend } = useGlobal();
// Get single component
const CompA = jsxBackend.get('ui.ComponentA');
// Get multiple components
const [CompB, CompC] = jsxBackend.all(['ui.ComponentB', 'ui.ComponentC']);route
Screen component
Example
/**
* @type: route
* name: RoomInfoEditView
* path: RoomInfoEditView
* group: root
* getId: route => 'RoomInfoEditView'
* mode: card_hide_tab
*/Properties
name: Alias of the screen.
-
Name rules
Syntax Prefix Suffix Description Example ScreenNameScreen component. CreateStoryScreenmodule_name.ScreenNameScreen belongs to module_name.core.error403module_name.home.home Main list screen belongs to module_name.blog.homemodule_name.resource_name.show.show Detail screen belongs to module_name,resource_name.event.pending_post.showmodule_name.resource_name.searchItem.searchItem Search screen belongs to module_name,resource_name.group.group_request.searchItemmodule_name.resource_name.searchItemOnTab.searchItemOnTab Search screen of a list in tab belongs to module_name,resource_name.group.group.searchItemOnTabsearch. module_name.ScreenNamesearch. Global search screen. search.search.defer
path: List of paths used to navigate to current screen.
-
Rules:
- A screen can have multiple
path. - Separate each
pathwith a comma,. - A parameter of a
pathis placed after a colon:(event/:id). - You can limit the allowed values for a parameter by adding these values in parentheses
(), separated by a pipe|(/:tab(viewAll|viewMyBlogs)).
- A screen can have multiple
-
Name rules:
Some
pathsyntax for special screens.Screen Name Path Syntax Description Example module_name.home/ module_nameMain list screen belongs to module_name./group/ module_name/:tab(actionName1|actionName2)Main list screen belongs to module_namewithactionName./group/:tab(viewAll|viewMyGroups|viewMyPendingGroups)/ module_name/:resource_name/:tab(actionName1|actionName2)Main list screen belongs to module_name,resource_namewithactionName./group/:resource_name/:tab(all|viewHosting|friend|past)module_name.resource_name.show/ module_name/:idDetail screen belongs to module_namewithid./marketplace/:id/ module_name/resource_name/:idDetail screen belongs to module_name,resource_namewithid./marketplace/marketplace_invoice/:idmodule_name.resource_name.searchItem/search/ module_name/resource_name/searchItemSearch screen belongs to module_name,resource_name./search/group/group/searchItemmodule_name.resource_name.searchItemOnTab/search/ module_name/resource_name/searchItemOnTabSearch screen of a list in tab belongs to module_name,resource_name./search/group/group/searchItemOnTab
group(optional): Group type.
If group isn't declared, the screen is accessible only when the user is logged in.
-
auth- Screen is used for authentication.
- Screen is accessible only when the user is not logged in.
-
root- Screen can be used regardless of user login status.
getId(optional): Callback to return an unique ID to use for the screen (Used by library react-navigation).
mode(optional): Display mode of the screen.
| Mode | Header | Bottom Tab | Description |
|---|---|---|---|
card(default) | X | X | Normal mode. |
card_hide_tab | X | Normal mode with no bottom tab. | |
modal | Modal mode with no header (Configuration: modalScreenOptions). | ||
overlay | Modal mode with no header for media modules (Configuration: modalScreenOptions). | ||
modalWithHeader | X | Normal mode with header (Used for Form screens in group auth). |
Usage
| Property | Usage | Example |
|---|---|---|
name | navigationBackend.push(name, ...otherProps) | navigationBackend.push('form.edit') |
navigationBackend.replace(name, ...otherProps) | ||
navigationBackend.navigate(name, ...otherProps) | ||
navigationBackend.push(name, ...otherProps) | ||
path | navigationBackend.openLink(path, ...otherProps) | navigationBackend.openLink('/group')navigationBackend.openLink('user/${item.id}') |
saga
Example
/**
* @type: saga
* name: featured
*/Properties
name: Alias of the saga.
siteDock
Single instance components or screens that can be used everywhere.
Example
/**
* @type: siteDock
* name: ReactionController
*/Properties
name: Alias of the component.
Usage
- Get the instance from hook
useGlobal.
const { i18n, reactionBackend, toastBackend } = useGlobal();
reactionBackend.show();
toastBackend.show({
message: i18n.formatMessage({ id: 'copied_to_clipboard' })
});reducer
Example
/**
* @type: reducer
* name: pagination
*/Properties
name: Alias of the reducer.
service
Global utility functions.
Example
/**
* @type: service
* name: uiControllerBackend
*/Properties
name: Alias of the utility.
Usage
- Use in React component.
const { navigationBackend } = useGlobal();
navigationBackend.push('form.edit');- Use in saga function.
const { navigationBackend } = yield* getGlobalContext();
yield call(navigationBackend.push, 'form.edit');middleware
App's middleware components.
Example
/**
* @type: middleware
* name: AppFirebase
*/Properties
name: Alias of the middleware.
polyfills
App's polyfills.
Example
/**
* @type: polyfills
* name: voip.polyfills
*/