Skip to main content
Version: 1.0.110

Creating a screen

Easy way to create a Screen

Adding single screen:

When using Nano, creating components is little bit different from a typical react native project. In Nano, we create component in the form of JSON and add it to RNNano component. Nano will render the component on screen.

For example, below is the text component.


import { NANO } from 'react-native-nano';

const text = {
component: NANO.TEXT,
name: 'text',
value: 'This is the sample text',
props: {
style: {

},
},
};


const screen = {
name: 'WelcomeScreen',
screen: {
v1: [text],
},
style: { flex: 1, justifyContent: 'center' },
};

nano makes it easy to place components in horizontal and vertical directions in a screen. it uses horizontal and vertical keys read more about them here. And after that simply add it to the RNNano component like below

import {RNNano} from  'react-native-nano';
...
const App = () => {
return <RNNano screens={[screen]} />;
};
export default App;

Nano uses react-native-paper components by default.

Adding multiple Screens:

You can actually add as many screens as you want to RNNano component just like below

const  App = () => {
return <RNNano screens={[
screen1,
screen2,
screen3,
screen4
...

]} />;
};
export default App;

Component Parameters:

While creating components in JSON structure, these are the keys can be implemented.

 
KeysRequiredDescription
componentyesThe name of the inbuilt  component see here for the whole list.
nameyesThe unique name one must provide for later use with no spaces.
valuenoThe default value of the component if it is input component, otherwise leave it.
propsnoprops related to that component, see react-native-paper
contentnoit takes another component as JSON. It will be nested inside. It will only be used when there is possibility of nesting. Ex: NANO.VIEW
animationnoNano uses react-native-animatable to make animations work, for example animation value can be
{ 
animation:"rotate",
duration:100,
delay:1000
}
hidenoif hide is 'true', component will be removed
platformnoYou can set this for rendering component only for specfific platforms. Example, `android|ios|web`, `android`, `ios`, `ios|android` etc. if not specified, component will be rendered in all platforms(web, android and ios).
networknoYou can connect to remote server see here for more deatils
onPressnoonPress method is called when user clicks on the component.
onLongPressnoonLongPress method is called when user long clicks on the component.

Screen Parameters:

While creating screen components in JSON structure, these are the keys can be implemented.

 
KeysRequiredDescription
nameyesThe unique name of the screen in with no spaces, example WelcomeScreen and LoginScreen .etc.
screenyesAdd all the screen components to this key in either using vertical (v1, v2, v3, v4, v5 ..... vn ) or horizontal (h1, h2, h3, h4, h5 ..... hn) keys. for more details check here.
stylenoThe style to apply for parent view of the screen.
onStartnoThis method is called when screen is mounted.
onEndnoThis is method is called when screen is unmounted
screenPropsnoYou can add all the screen props those available to Stack.Screen in react-navigation
logicnoInstead of implementing methods to onPress or onLongPress or any other methods directly in JSON structure for a component, you can provide those methods here in an object. For example,
{ 
"onButtonPress": ({setUi, getUi, moduleParams}) => {

// do something here

}
}

and then you can reference this method in your component like this

const button = {
component: NANO.BUTTON,
name: 'button',
onPress: 'onButtonPress'
};