Site icon C1CTech

ReactNative Navigation Example

<h3><span style&equals;"color&colon; &num;000080&semi;">React Native Navigation<&sol;span><&sol;h3>&NewLine;<p>React Native Navigation provides 100&percnt; native platform navigation on both <strong><span style&equals;"color&colon; &num;0000ff&semi;">iOS<&sol;span><&sol;strong> and <strong><span style&equals;"color&colon; &num;0000ff&semi;">Android<&sol;span><&sol;strong> for React Native apps&period;<&sol;p>&NewLine;<p>In this tutorial I will demonstrate you how to install <strong><span style&equals;"color&colon; &num;0000ff&semi;">react-native-navigation<&sol;span><&sol;strong> in your app&comma; work with singlescreen &lpar;without tab&rpar;&comma; work with tabbased screen&comma; Navigating forward&comma; Navigating backward&period;<&sol;p>&NewLine;<p>Get <strong>GITHUB<&sol;strong> code from <a href&equals;"https&colon;&sol;&sol;github&period;com&sol;arunk7839&sol;ReactNativeNavigationExample"><strong><span style&equals;"color&colon; &num;00ff00&semi;">HERE<&sol;span><&sol;strong><&sol;a>&period;<&sol;p>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p><amp-youtube layout&equals;"responsive" width&equals;"1200" height&equals;"675" data-videoid&equals;"IOoenO4L0as" title&equals;"React Native Navigation Example"><a placeholder href&equals;"https&colon;&sol;&sol;youtu&period;be&sol;IOoenO4L0as"><img src&equals;"https&colon;&sol;&sol;i&period;ytimg&period;com&sol;vi&sol;IOoenO4L0as&sol;hqdefault&period;jpg" layout&equals;"fill" object-fit&equals;"cover" alt&equals;"React Native Navigation Example"><&sol;a><&sol;amp-youtube><&sol;p>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;">Adding React Native Navigation To Android<&sol;span><&sol;h3>&NewLine;<ul>&NewLine;<li>Install <strong><span style&equals;"color&colon; &num;008000&semi;">react-native-navigation<&sol;span><&sol;strong> latest stable version&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<pre style&equals;"padding-left&colon; 30px&semi;"><span style&equals;"color&colon; &num;0000ff&semi;">npm install --save react-native-navigation&commat;latest<&sol;span><&sol;pre>&NewLine;<ul>&NewLine;<li>Add the following in <strong><span style&equals;"color&colon; &num;008000&semi;">android&sol;settings&period;gradle<&sol;span><&sol;strong>&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<pre style&equals;"padding-left&colon; 30px&semi;"><code>include '&colon;react-native-navigation'&NewLine;project&lpar;'&colon;react-native-navigation'&rpar;&period;projectDir &equals; new File&lpar;rootProject&period;projectDir&comma; '&period;&period;&sol;node&lowbar;modules&sol;react-native-navigation&sol;android&sol;app&sol;'&rpar;<&sol;code><&sol;pre>&NewLine;<ul>&NewLine;<li>Update project dependencies in <span style&equals;"color&colon; &num;008000&semi;"><strong>android&sol;app&sol;build&period;gradle<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<pre style&equals;"padding-left&colon; 30px&semi;"><code>android &lbrace;&NewLine;&NewLine;<span style&equals;"color&colon; &num;0000ff&semi;"><strong>compileSdkVersion 25 <&sol;strong>&NewLine;&NewLine;<strong>buildToolsVersion "25&period;0&period;1"<&sol;strong>&NewLine;&NewLine;&period;&period;&period; &rcub;<&sol;span>&NewLine;&NewLine;dependencies &lbrace;&NewLine;&NewLine;<span style&equals;"color&colon; &num;0000ff&semi;"><strong>compile fileTree&lpar;dir&colon; "libs"&comma; include&colon; &lbrack;"&ast;&period;jar"&rsqb;&rpar; <&sol;strong>&NewLine;&NewLine;<strong>compile "com&period;android&period;support&colon;appcompat-v7&colon;23&period;0&period;1" <&sol;strong>&NewLine;&NewLine;<strong>compile "com&period;facebook&period;react&colon;react-native&colon;&plus;" <&sol;strong>&NewLine;&NewLine;<&sol;span><span style&equals;"color&colon; &num;008000&semi;"><strong><span style&equals;"color&colon; &num;0000ff&semi;">compile project&lpar;'&colon;react-native-navigation'&rpar;<&sol;span> <&sol;strong><&sol;span>&NewLine;&NewLine;&rcub;<&sol;code><&sol;pre>&NewLine;<ul>&NewLine;<li>In <strong><span style&equals;"color&colon; &num;008000&semi;">MainActivity&period;java<&sol;span><&sol;strong> it should extend  <span style&equals;"color&colon; &num;008000&semi;"><strong>com&period;reactnativenavigation&period;controllers&period;SplashActivity  <&sol;strong><&sol;span>instead of <span style&equals;"color&colon; &num;008000&semi;"><strong>ReactActivity<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<pre style&equals;"padding-left&colon; 30px&semi;"><code>import com&period;reactnativenavigation&period;controllers&period;SplashActivity&semi; &NewLine;&NewLine;public class MainActivity extends SplashActivity &lbrace; &NewLine;&NewLine;&rcub;&NewLine;<&sol;code><&sol;pre>&NewLine;<p>If you have any <span style&equals;"color&colon; &num;008000&semi;"><strong>react-native<&sol;strong><&sol;span> related methods&comma; you can safely delete them&period;<&sol;p>&NewLine;<ul>&NewLine;<li>In <strong><span style&equals;"color&colon; &num;008000&semi;">MainApplication&period;java <&sol;span><&sol;strong>&comma; add the following<&sol;li>&NewLine;<&sol;ul>&NewLine;<pre style&equals;"padding-left&colon; 30px&semi;"><span style&equals;"color&colon; &num;0000ff&semi;">&sol;&sol;react-native-navigation<&sol;span>&NewLine;import com&period;reactnativenavigation&period;NavigationApplication&semi;<&sol;pre>&NewLine;<pre style&equals;"padding-left&colon; 30px&semi;">public class MainApplication extends NavigationApplication &lbrace;&NewLine;&NewLine; &commat;Override&NewLine; public boolean isDebug&lpar;&rpar; &lbrace;&NewLine; <span style&equals;"color&colon; &num;0000ff&semi;">&sol;&sol; Make sure you are using BuildConfig from your own application<&sol;span>&NewLine; return BuildConfig&period;DEBUG&semi;&NewLine; &rcub;&NewLine;&NewLine; protected List&lt&semi;ReactPackage&gt&semi; getPackages&lpar;&rpar; &lbrace;&NewLine; <span style&equals;"color&colon; &num;0000ff&semi;">&sol;&sol; Add additional packages you require here&NewLine; &sol;&sol; No need to add RnnPackage and MainReactPackage<&sol;span>&NewLine; return Arrays&period;&lt&semi;ReactPackage&gt&semi;asList&lpar;&NewLine; &sol;&sol;eg&period;&period;new VectorIconsPackage&lpar;&rpar;&NewLine; &rpar;&semi;&NewLine; &rcub;&NewLine;&NewLine; &commat;Override&NewLine; public List&lt&semi;ReactPackage&gt&semi; createAdditionalReactPackages&lpar;&rpar; &lbrace;&NewLine; return getPackages&lpar;&rpar;&semi;&NewLine; &rcub;&NewLine;&NewLine;<span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;if you are using <span style&equals;"color&colon; &num;0000ff&semi;">index&period;js<&sol;span> as your entry point instead of <span style&equals;"color&colon; &num;0000ff&semi;">index&period;ios&period;js<&sol;span> and <span style&equals;"color&colon; &num;0000ff&semi;">index&period;android&period;js&NewLine;<&sol;span><&sol;span> <span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;&lpar;it is the default since React Native 0&period;49&rpar;&period; <&sol;span> &NewLine;&NewLine;&commat;Override public String getJSMainModuleName&lpar;&rpar; &lbrace; &NewLine;return "index"&semi; &rcub; &NewLine;&rcub;<&sol;pre>&NewLine;<p style&equals;"padding-left&colon; 30px&semi;">Make sure that <code>isDebug<&sol;code> and <code>createAdditionalReactPackages<&sol;code> methods are implemented&period;<&sol;p>&NewLine;<ul>&NewLine;<li>Update <strong><span style&equals;"color&colon; &num;008000&semi;">AndroidManifest&period;xml<&sol;span><&sol;strong> and set <span style&equals;"color&colon; &num;0000ff&semi;"><strong>android&colon;name<&sol;strong><&sol;span> value to &period;<strong><span style&equals;"color&colon; &num;008000&semi;">MainApplication<&sol;span><&sol;strong><&sol;li>&NewLine;<&sol;ul>&NewLine;<pre style&equals;"padding-left&colon; 30px&semi;"><span style&equals;"color&colon; &num;0000ff&semi;"><span class&equals;"token tag"><span class&equals;"token punctuation">&lt&semi;<&sol;span>application<&sol;span>&NewLine;&NewLine;<span class&equals;"token attr-name"><span class&equals;"token namespace">android&colon;<&sol;span>name<&sol;span><span class&equals;"token attr-value"><span class&equals;"token punctuation">&equals;<&sol;span><span class&equals;"token punctuation">"<&sol;span>&period;MainApplication<span class&equals;"token punctuation">"<&sol;span><&sol;span>&NewLine;&NewLine;<span class&equals;"token attr-name">&period;&period;&period;<&sol;span> <span class&equals;"token punctuation">&sol;&gt&semi;<&sol;span><&sol;span><&sol;pre>&NewLine;<h3><&sol;h3>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;">Registering and Rendering a Screen<&sol;span><&sol;h3>&NewLine;<p>Before loading screen into our app  firstly we must  have to register the screen using Navigation&period;<&sol;p>&NewLine;<pre><code>import &lbrace; Navigation &rcub; from "react-native-navigation"&semi;&NewLine;import MainScreen from "&period;&sol;src&sol;screens&sol;MainScreen&sol;MainScreen"&semi;&NewLine;<span style&equals;"color&colon; &num;0000ff&semi;">&sol;&sol; Register Screens<&sol;span>&NewLine;Navigation&period;registerComponent&lpar;&NewLine; "navigation-example&period;MainScreen"&comma;&NewLine; &lpar;&rpar; &equals;&gt&semi; MainScreen&rpar;&semi;<&sol;code><&sol;pre>&NewLine;<p>Now there is no need to write&colon;<&sol;p>&NewLine;<pre><code>AppRegistry&period;registerComponent&lpar;'NavigationExample'&comma; &lpar;&rpar; &equals;&gt&semi; App&rpar;&semi;  <&sol;code> in <span style&equals;"color&colon; &num;008000&semi;">index&period;js<&sol;span><&sol;pre>&NewLine;<p>Now Navigation object provided by the react-native-navigation will tell us our react app which screen is to render<br &sol;>&NewLine;first&period;Here I am starting App using <strong><span style&equals;"color&colon; &num;008000&semi;">startSingleScreenApp<&sol;span><&sol;strong> you can also use <strong><span style&equals;"color&colon; &num;008000&semi;">startTabBasedApp<&sol;span><&sol;strong> if you want tabs&period;<&sol;p>&NewLine;<pre><code><span style&equals;"color&colon; &num;0000ff&semi;">&sol;&sol; Starting App<&sol;span>&NewLine;&NewLine;Navigation&period;startSingleScreenApp&lpar;&lbrace;&NewLine; screen&colon; &lbrace;&NewLine; screen&colon; "navigation-example&period;MainScreen"&comma;&NewLine; title&colon; "Entertainment"&NewLine; &rcub;&NewLine;&rcub;&rpar;&semi;<&sol;code><&sol;pre>&NewLine;<h3><&sol;h3>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;">Adding a Tab Screen &lpar;Tabs Navigation&rpar;<&sol;span><&sol;h3>&NewLine;<p>For Tabs Navigation we use <span style&equals;"color&colon; &num;008000&semi;"><strong>startTabBasedApp&lpar;&rpar;<&sol;strong><&sol;span> inside this function we define array of tabs using <strong><span style&equals;"color&colon; &num;0000ff&semi;">tabs<&sol;span><&sol;strong> property&period;We can also use <strong><span style&equals;"color&colon; &num;0000ff&semi;">tabStyle<&sol;span><&sol;strong>&lpar;ios&rpar;&comma;<strong><span style&equals;"color&colon; &num;0000ff&semi;">appStyle<&sol;span><&sol;strong> &lpar;android&rpar; for tab styling&period;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;000080&semi;"><strong>Note<&sol;strong><&sol;span>&colon;  Tabs without icon works on ios but not  on android&period;For android we must have to define icon property&period;For more detail you can visit <span style&equals;"color&colon; &num;0000ff&semi;"><strong>here<&sol;strong><&sol;span>&period;<&sol;p>&NewLine;<p>Here in this tutorial  I have used <span style&equals;"color&colon; &num;008000&semi;"><strong>react-native-vector-icons<&sol;strong><&sol;span>&period; For installation you can visit to my this <span style&equals;"color&colon; &num;0000ff&semi;"><strong>tutorial<&sol;strong><&sol;span>&period;<&sol;p>&NewLine;<pre><code>import &lbrace; Navigation &rcub; from 'react-native-navigation'&semi;&NewLine;import &lbrace; Platform &rcub; from 'react-native'&semi;&NewLine;import Icon from 'react-native-vector-icons&sol;Ionicons'&semi;&NewLine;&NewLine;const startTabs &equals; &lpar;&rpar; &equals;&gt&semi; &lbrace;&NewLine; Promise&period;all&lpar;&lbrack;&NewLine; Icon&period;getImageSource&lpar;Platform&period;OS &equals;&equals;&equals; 'android' &quest; "md-videocam" &colon; "ios-videocam"&comma; 30&rpar;&comma;&NewLine; Icon&period;getImageSource&lpar;Platform&period;OS &equals;&equals;&equals; 'android' &quest; "md-musical-notes" &colon; "ios-musical-notes"&comma; 30&rpar;&comma;&NewLine; Icon&period;getImageSource&lpar;Platform&period;OS &equals;&equals;&equals; 'android' &quest; "md-easel" &colon; "ios-easel"&comma; 30&rpar;&NewLine; &NewLine; &rsqb;&rpar;&period;then&lpar;sources &equals;&gt&semi; &lbrace;&NewLine; Navigation&period;startTabBasedApp&lpar;&lbrace;&NewLine; tabs&colon; &lbrack;&NewLine; &lbrace;&NewLine; screen&colon; "navigation-example&period;Movies"&comma;&NewLine; label&colon; "Movies"&comma;&NewLine; title&colon; "Movies"&comma;&NewLine; icon&colon; sources&lbrack;0&rsqb;&comma;&NewLine;&NewLine;&NewLine; &rcub;&comma;&NewLine; &lbrace;&NewLine; screen&colon; "navigation-example&period;Plays"&comma;&NewLine; label&colon; "Plays"&comma;&NewLine; title&colon; "Plays"&comma;&NewLine; icon&colon; sources&lbrack;1&rsqb;&comma;&NewLine;&NewLine;&NewLine; &rcub;&comma;&NewLine; &lbrace;&NewLine; screen&colon; "navigation-example&period;Events"&comma;&NewLine; label&colon; "Events"&comma;&NewLine; title&colon; "Events"&comma;&NewLine; icon&colon; sources&lbrack;2&rsqb;&comma;&NewLine;&NewLine; &rcub;&NewLine; &rsqb;&comma;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;tabstyle only works for ios for android we have to use appstyle<&sol;span>&NewLine; tabsStyle&colon; &lbrace;&NewLine; tabBarSelectedButtonColor&colon; "orange"&NewLine; &rcub;&comma;&NewLine;&NewLine; appStyle&colon; &lbrace;&NewLine; tabBarSelectedButtonColor&colon; "orange"&NewLine; &rcub;&NewLine;&NewLine; &rcub;&rpar;&semi;&NewLine; &rcub;&rpar;&semi;&NewLine;&rcub;&semi;&NewLine;&NewLine;export default startTabs&semi;<&sol;code><&sol;pre>&NewLine;<p>The <span style&equals;"color&colon; &num;0000ff&semi;"><strong><code>Promise<&sol;code><&sol;strong><&sol;span> object represents the eventual completion &lpar;or failure&rpar; of an asynchronous operation&comma; and its resulting value&period;<&sol;p>&NewLine;<p>The <span style&equals;"color&colon; &num;0000ff&semi;"><code><strong>Promise&period;all&lpar;iterable&rpar;<&sol;strong><&sol;code><&sol;span> method returns a single <code>Promise<&sol;code> that resolves when all of the promises in the <code>iterable<&sol;code> argument have resolved or when the iterable argument contains no promises&period;<&sol;p>&NewLine;<&excl;-- WP QUADS Content Ad Plugin v&period; 2&period;0&period;98&period;1 -->&NewLine;<div class&equals;"quads-location quads-ad2" id&equals;"quads-ad2" style&equals;"float&colon;none&semi;margin&colon;0px&semi;">&NewLine;&NewLine;<&sol;div>&NewLine;&NewLine;<p>An <strong><a href&equals;"https&colon;&sol;&sol;developer&period;mozilla&period;org&sol;en-US&sol;docs&sol;Web&sol;JavaScript&sol;Reference&sol;Iteration&lowbar;protocols&num;The&lowbar;iterable&lowbar;protocol">iterable<&sol;a><&sol;strong> object such as an <code>Array<&sol;code> or <code>String<&sol;code><&sol;p>&NewLine;<h3><&sol;h3>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">Pushing Pages &lpar;Navigating Forward&rpar;<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>On button click or view  press if you  want to navigate to a new page &comma;navigator as a prop provided by the react-native make it possible&period;<&sol;p>&NewLine;<pre><code>onItemPressedHandler&equals; &lpar;name&comma;image&rpar;&equals;&gt&semi;&lbrace;&NewLine;&NewLine;this&period;props&period;navigator&period;push&lpar;&lbrace;&NewLine; screen&colon; "navigation-example&period;MovieDetail"&comma;&NewLine; title&colon; name&comma;&NewLine; passProps&colon; &lbrace;&NewLine; movieName&colon; name&comma;&NewLine; movieImage&colon; image&NewLine; &rcub;&NewLine; &rcub;&rpar;&semi;&NewLine;&rcub;<&sol;code><&sol;pre>&NewLine;<h3><&sol;h3>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">Poping Pages &lpar;Navigating Backward&rpar;<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>If you want to move back on previous page on some action you can use pop&lpar;&rpar; using navigator as a prop&period;<&sol;p>&NewLine;<pre><code>backHandler &equals; &lpar;&rpar;&equals;&gt&semi;&lbrace;&NewLine; this&period;props&period;navigator&period;pop&lpar;&rpar;&semi;&NewLine;&NewLine;&rcub;<&sol;code><&sol;pre>&NewLine;<h3><&sol;h3>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>START CODING &colon;<&sol;strong><&sol;span><&sol;h3>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>App&period;js<&sol;strong><&sol;span><&sol;p>&NewLine;<pre><code>import &lbrace; Navigation &rcub; from "react-native-navigation"&semi;&NewLine;import MainScreen from "&period;&sol;src&sol;screens&sol;MainScreen&sol;MainScreen"&semi;&NewLine;import MovieDetail from "&period;&sol;src&sol;screens&sol;MovieDetail&sol;MovieDetail"&semi;&NewLine;import Movies from "&period;&sol;src&sol;screens&sol;Movies&sol;Movies"&semi;&NewLine;import Plays from "&period;&sol;src&sol;screens&sol;Plays&sol;Plays"&semi;&NewLine;import Events from "&period;&sol;src&sol;screens&sol;Events&sol;Events"&semi;&NewLine;&NewLine;&sol;&sol; Register Screens&NewLine;Navigation&period;registerComponent&lpar;&NewLine; "navigation-example&period;MainScreen"&comma;&NewLine; &lpar;&rpar; &equals;&gt&semi; MainScreen&rpar;&semi;&NewLine;&NewLine; Navigation&period;registerComponent&lpar;&NewLine; "navigation-example&period;Movies"&comma;&NewLine; &lpar;&rpar; &equals;&gt&semi; Movies&rpar;&semi;&NewLine;&NewLine; Navigation&period;registerComponent&lpar;&NewLine; "navigation-example&period;Plays"&comma;&NewLine; &lpar;&rpar; &equals;&gt&semi; Plays&rpar;&semi;&NewLine;&NewLine; Navigation&period;registerComponent&lpar;&NewLine; "navigation-example&period;Events"&comma;&NewLine; &lpar;&rpar; &equals;&gt&semi; Events&rpar;&semi;&NewLine;&NewLine; Navigation&period;registerComponent&lpar;&NewLine; "navigation-example&period;MovieDetail"&comma;&NewLine; &lpar;&rpar; &equals;&gt&semi; MovieDetail&rpar;&semi;&NewLine;&NewLine;&NewLine;&NewLine;&sol;&sol; Starting App&NewLine;Navigation&period;startSingleScreenApp&lpar;&lbrace;&NewLine; screen&colon; &lbrace;&NewLine; screen&colon; "navigation-example&period;MainScreen"&comma;&NewLine; title&colon; "Entertainment"&NewLine; &rcub;&NewLine;&rcub;&rpar;&semi;<&sol;code><&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>MainScreen&period;js<&sol;strong><&sol;span><&sol;p>&NewLine;<pre><code>import React&comma; &lbrace; Component &rcub; from "react"&semi;&NewLine;import &lbrace;View&comma;Text&comma;Button&comma;StyleSheet&rcub; from "react-native"&semi;&NewLine;import StartMainTabs from "&period;&period;&sol;MainTabs&sol;StartMainTabs"&semi;&NewLine;&NewLine;&NewLine;class MainScreen extends Component&lbrace;&NewLine;&NewLine;&NewLine;nextHandler &equals; &lpar;&rpar;&equals;&gt&semi;&lbrace;&NewLine;StartMainTabs&lpar;&rpar;&semi;&NewLine;&NewLine;&rcub;&NewLine;render&lpar;&rpar;&lbrace;&NewLine;&NewLine;return&lpar;&NewLine;&lt&semi;View style&equals;&lbrace;styles&period;container&rcub;&gt&semi;&NewLine;&lt&semi;Text style&equals;&lbrace;styles&period;titleText&rcub; &gt&semi;Entertainment&lt&semi;&sol;Text&gt&semi;&NewLine;&lt&semi;Button color&equals;"&num;841584" title&equals;"Next" onPress&equals;&lbrace;this&period;nextHandler&rcub;&sol;&gt&semi;&NewLine;&lt&semi;&sol;View&gt&semi;&NewLine;&rpar;&semi;&NewLine;&rcub;&NewLine;&NewLine;&rcub;&NewLine;&NewLine;const styles &equals; StyleSheet&period;create&lpar;&lbrace;&NewLine; container&colon; &lbrace;&NewLine; flex&colon; 1&comma;&NewLine; alignItems&colon; "center"&comma;&NewLine; justifyContent&colon; 'center'&comma;&NewLine; backgroundColor&colon;"&num;521751"&NewLine; &rcub;&comma;&NewLine; titleText&colon; &lbrace;&NewLine; fontSize&colon; 50&comma;&NewLine; fontWeight&colon; 'bold'&comma;&NewLine; color&colon; "&num;fa923f"&NewLine; &rcub;&NewLine; &rcub;&rpar;&semi;&NewLine;export default MainScreen&semi;<&sol;code><&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">StartMainTabs&period;js<&sol;span><&sol;strong><&sol;p>&NewLine;<pre><code>import &lbrace; Navigation &rcub; from 'react-native-navigation'&semi;&NewLine;import &lbrace; Platform &rcub; from 'react-native'&semi;&NewLine;import Icon from 'react-native-vector-icons&sol;Ionicons'&semi;&NewLine;&NewLine;const startTabs &equals; &lpar;&rpar; &equals;&gt&semi; &lbrace;&NewLine; Promise&period;all&lpar;&lbrack;&NewLine; Icon&period;getImageSource&lpar;Platform&period;OS &equals;&equals;&equals; 'android' &quest; "md-videocam" &colon; "ios-videocam"&comma; 30&rpar;&comma;&NewLine; Icon&period;getImageSource&lpar;Platform&period;OS &equals;&equals;&equals; 'android' &quest; "md-musical-notes" &colon; "ios-musical-notes"&comma; 30&rpar;&comma;&NewLine; Icon&period;getImageSource&lpar;Platform&period;OS &equals;&equals;&equals; 'android' &quest; "md-easel" &colon; "ios-easel"&comma; 30&rpar;&comma;&NewLine;&NewLine; &rsqb;&rpar;&period;then&lpar;sources &equals;&gt&semi; &lbrace;&NewLine; Navigation&period;startTabBasedApp&lpar;&lbrace;&NewLine; tabs&colon; &lbrack;&NewLine; &lbrace;&NewLine; screen&colon; "navigation-example&period;Movies"&comma;&NewLine; label&colon; "Movies"&comma;&NewLine; title&colon; "Movies"&comma;&NewLine; icon&colon; sources&lbrack;0&rsqb;&comma;&NewLine;&NewLine;&NewLine; &rcub;&comma;&NewLine; &lbrace;&NewLine; screen&colon; "navigation-example&period;Plays"&comma;&NewLine; label&colon; "Plays"&comma;&NewLine; title&colon; "Plays"&comma;&NewLine; icon&colon; sources&lbrack;1&rsqb;&comma;&NewLine;&NewLine;&NewLine; &rcub;&comma;&NewLine; &lbrace;&NewLine; screen&colon; "navigation-example&period;Events"&comma;&NewLine; label&colon; "Events"&comma;&NewLine; title&colon; "Events"&comma;&NewLine; icon&colon; sources&lbrack;2&rsqb;&comma;&NewLine; &rcub;&NewLine; &rsqb;&comma;&NewLine; tabsStyle&colon; &lbrace;&NewLine; tabBarSelectedButtonColor&colon; "orange"&NewLine; &rcub;&comma;&NewLine;&NewLine; appStyle&colon; &lbrace;&NewLine; tabBarSelectedButtonColor&colon; "orange"&NewLine; &rcub;&NewLine;&NewLine; &rcub;&rpar;&semi;&NewLine; &rcub;&rpar;&semi;&NewLine;&rcub;&semi;&NewLine;&NewLine;export default startTabs&semi;<&sol;code><&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">Movies&period;js<&sol;span><&sol;strong><&sol;p>&NewLine;<pre><code>import React&comma; &lbrace; Component &rcub; from "react"&semi;&NewLine;import &lbrace;StyleSheet&comma; FlatList&rcub; from "react-native"&semi;&NewLine;import movieImageOne from "&period;&period;&sol;&period;&period;&sol;assets&sol;black&lowbar;panther&period;jpg"&semi;&NewLine;import movieImageTwo from "&period;&period;&sol;&period;&period;&sol;assets&sol;death&lowbar;of&lowbar;stalin&period;jpg"&semi;&NewLine;import movieImageThree from "&period;&period;&sol;&period;&period;&sol;assets&sol;the&lowbar;rider&period;jpg"&semi;&NewLine;import movieImageFour from "&period;&period;&sol;&period;&period;&sol;assets&sol;zama&period;jpg"&semi;&NewLine;import movieImageFive from "&period;&period;&sol;&period;&period;&sol;assets&sol;annhilation&period;jpg"&semi;&NewLine;import ListItem from "&period;&period;&sol;&period;&period;&sol;component&sol;ListItem&sol;ListItem"&semi;&NewLine;&NewLine;&NewLine;class Movies extends Component&lbrace;&NewLine;&NewLine;&NewLine;onItemPressedHandler&equals; &lpar;name&comma;image&rpar;&equals;&gt&semi;&lbrace;&NewLine;&NewLine;this&period;props&period;navigator&period;push&lpar;&lbrace;&NewLine; screen&colon; "navigation-example&period;MovieDetail"&comma;&NewLine; title&colon; name&comma;&NewLine; passProps&colon; &lbrace;&NewLine; movieName&colon; name&comma;&NewLine; movieImage&colon; image&NewLine; &rcub;&NewLine; &rcub;&rpar;&semi;&NewLine;&rcub;&NewLine;render&lpar;&rpar;&lbrace;&NewLine;&NewLine;return&lpar;&NewLine; &lt&semi;FlatList&NewLine; style&equals;&lbrace;styles&period;listContainer&rcub;&NewLine; data&equals;&lbrace;&lbrack;&NewLine; &lbrace; movieName&colon; 'Black Panther'&comma;&NewLine; movieImage&colon; movieImageOne&comma;&NewLine; key&colon; 'a'&NewLine; &rcub;&comma;&NewLine; &lbrace; movieName&colon; 'The Death of Stalin'&comma;&NewLine; movieImage&colon; movieImageTwo&comma;&NewLine; key&colon; 'b'&NewLine; &rcub;&comma;&NewLine; &lbrace; movieName&colon; 'The Rider'&comma;&NewLine; movieImage&colon; movieImageThree&comma;&NewLine; key&colon; 'c'&NewLine; &rcub;&comma;&NewLine; &lbrace; movieName&colon; 'Zama'&comma;&NewLine; movieImage&colon; movieImageFour&comma;&NewLine; key&colon; 'd'&NewLine; &rcub;&comma;&NewLine; &lbrace; movieName&colon; 'Annihilation'&comma;&NewLine; movieImage&colon; movieImageFive&comma;&NewLine; key&colon; 'e'&NewLine; &rcub;&comma;&NewLine; &rsqb;&rcub;&NewLine;&NewLine; renderItem&equals;&lbrace;&lpar;info&rpar; &equals;&gt&semi; &lpar;&NewLine; &lt&semi;ListItem&NewLine; movieName&equals;&lbrace;info&period;item&period;movieName&rcub;&NewLine; movieImage&equals;&lbrace;info&period;item&period;movieImage&rcub;&NewLine; onItemPressed&equals;&lbrace;&lpar;&rpar; &equals;&gt&semi; this&period;onItemPressedHandler&lpar;info&period;item&period;movieName&comma;info&period;item&period;movieImage&rpar;&rcub;&NewLine; &sol;&gt&semi;&NewLine; &rpar;&rcub;&NewLine; &sol;&gt&semi;&NewLine;&rpar;&semi;&NewLine;&rcub;&NewLine;&NewLine;&rcub;&NewLine;const styles &equals; StyleSheet&period;create&lpar;&lbrace;&NewLine; listContainer&colon; &lbrace;&NewLine; width&colon; "100&percnt;"&NewLine; &rcub;&NewLine;&rcub;&rpar;&semi;&NewLine;&NewLine;export default Movies&semi;<&sol;code><&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">Plays&period;js<&sol;span><&sol;strong><&sol;p>&NewLine;<pre><code>import React&comma; &lbrace; Component &rcub; from "react"&semi;&NewLine;import &lbrace;View&comma;Text&comma;StyleSheet&rcub; from "react-native"&semi;&NewLine;&NewLine;&NewLine;class Plays extends Component&lbrace;&NewLine;&NewLine;render&lpar;&rpar;&lbrace;&NewLine;&NewLine;return&lpar;&NewLine;&lt&semi;View style&equals;&lbrace;styles&period;container&rcub;&gt&semi;&NewLine;&lt&semi;Text style&equals;&lbrace;styles&period;titleText&rcub;&gt&semi;Plays&lt&semi;&sol;Text&gt&semi;&NewLine;&lt&semi;&sol;View&gt&semi;&NewLine;&rpar;&semi;&NewLine;&rcub;&NewLine;&NewLine;&rcub;&NewLine;&NewLine;const styles &equals; StyleSheet&period;create&lpar;&lbrace;&NewLine; container&colon; &lbrace;&NewLine; flex&colon; 1&comma;&NewLine; alignItems&colon; "center"&comma;&NewLine; justifyContent&colon; 'center'&comma;&NewLine; backgroundColor&colon;"&num;6a5acd"&NewLine; &rcub;&comma;&NewLine; titleText&colon; &lbrace;&NewLine; fontSize&colon; 50&comma;&NewLine; fontWeight&colon; 'bold'&comma;&NewLine; color&colon; "&num;fa923f"&NewLine; &rcub;&NewLine; &rcub;&rpar;&semi;&NewLine;export default Plays&semi;<&sol;code><&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">Events&period;js<&sol;span><&sol;strong><&sol;p>&NewLine;<pre><code>import React&comma; &lbrace; Component &rcub; from "react"&semi;&NewLine;import &lbrace;View&comma;Text&comma;StyleSheet&rcub; from "react-native"&semi;&NewLine;&NewLine;&NewLine;class Events extends Component&lbrace;&NewLine;&NewLine;render&lpar;&rpar;&lbrace;&NewLine;&NewLine;return&lpar;&NewLine;&lt&semi;View style&equals;&lbrace;styles&period;container&rcub;&gt&semi;&NewLine;&lt&semi;Text style&equals;&lbrace;styles&period;titleText&rcub;&gt&semi;Events&lt&semi;&sol;Text&gt&semi;&NewLine;&lt&semi;&sol;View&gt&semi;&NewLine;&rpar;&semi;&NewLine;&rcub;&NewLine;&NewLine;&rcub;&NewLine;&NewLine;const styles &equals; StyleSheet&period;create&lpar;&lbrace;&NewLine; container&colon; &lbrace;&NewLine; flex&colon; 1&comma;&NewLine; alignItems&colon; "center"&comma;&NewLine; justifyContent&colon; 'center'&comma;&NewLine; backgroundColor&colon;"&num;228b22"&NewLine; &rcub;&comma;&NewLine; titleText&colon; &lbrace;&NewLine; fontSize&colon; 50&comma;&NewLine; fontWeight&colon; 'bold'&comma;&NewLine; color&colon; "&num;fa923f"&NewLine; &rcub;&NewLine; &rcub;&rpar;&semi;&NewLine;export default Events&semi;<&sol;code><&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">MovieDetail&period;js<&sol;span><&sol;strong><&sol;p>&NewLine;<pre><code>import React&comma; &lbrace; Component &rcub; from "react"&semi;&NewLine;import &lbrace;View&comma;Text&comma;StyleSheet&comma;Image&comma;Button&rcub; from "react-native"&semi;&NewLine;&NewLine;&NewLine;class MovieDetail extends Component&lbrace;&NewLine;&NewLine;&NewLine;backHandler &equals; &lpar;&rpar;&equals;&gt&semi;&lbrace;&NewLine; this&period;props&period;navigator&period;pop&lpar;&rpar;&semi;&NewLine;&NewLine;&rcub;&NewLine;&NewLine;render&lpar;&rpar;&lbrace;&NewLine;&NewLine;return&lpar;&NewLine;&lt&semi;View style&equals;&lbrace;styles&period;container&rcub;&gt&semi;&NewLine; &lt&semi;Image&NewLine; source&equals;&lbrace;this&period;props&period;movieImage&rcub;&NewLine; style&equals;&lbrace;styles&period;movieImage&rcub;&NewLine; &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;Text style&equals;&lbrace;styles&period;movieName&rcub;&gt&semi;&NewLine; &lbrace;this&period;props&period;movieName&rcub;&NewLine; &lt&semi;&sol;Text&gt&semi;&NewLine; &lt&semi;Button color&equals;"&num;841584" title&equals;"Back" onPress&equals;&lbrace;this&period;backHandler&rcub;&sol;&gt&semi;&NewLine; &lt&semi;&sol;View&gt&semi;&NewLine; &rpar;&semi;&NewLine;&rcub;&NewLine;&NewLine;&rcub;&NewLine;&NewLine;const styles &equals; StyleSheet&period;create&lpar;&lbrace;&NewLine; container&colon; &lbrace;&NewLine;&NewLine; flex&colon; 1&comma;&NewLine; padding&colon;50&comma;&NewLine;&NewLine;&NewLine; alignItems&colon; "center"&comma;&NewLine; justifyContent&colon; 'center'&NewLine; &rcub;&comma;&NewLine; movieImage&colon; &lbrace;&NewLine; width&colon; "100&percnt;"&comma;&NewLine; height&colon; "100&percnt;"&NewLine; &rcub;&comma;&NewLine; movieName&colon; &lbrace;&NewLine; fontWeight&colon; "bold"&comma;&NewLine; textAlign&colon; "center"&comma;&NewLine; fontSize&colon; 30&comma;&NewLine; color&colon; "&num;521751"&comma;&NewLine;&NewLine; &rcub;&NewLine; &rcub;&rpar;&semi;&NewLine;export default MovieDetail&semi;<&sol;code><&sol;pre>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">ListItem&period;js<&sol;span><&sol;strong><&sol;p>&NewLine;<pre><code>import React from "react"&semi;&NewLine;import &lbrace; View&comma; Text&comma; StyleSheet&comma; TouchableOpacity&comma; Image &rcub; from "react-native"&semi;&NewLine;&NewLine;const listItem &equals; props &equals;&gt&semi; &lpar;&NewLine; &lt&semi;TouchableOpacity onPress&equals;&lbrace;props&period;onItemPressed&rcub;&gt&semi;&NewLine; &lt&semi;View style&equals;&lbrace;styles&period;listItem&rcub;&gt&semi;&NewLine; &lt&semi;Image resizeMode&equals;"cover" source&equals;&lbrace;props&period;movieImage&rcub; style&equals;&lbrace;styles&period;movieImage&rcub; &sol;&gt&semi;&NewLine; &lt&semi;Text&gt&semi;&lbrace;props&period;movieName&rcub;&lt&semi;&sol;Text&gt&semi;&NewLine; &lt&semi;&sol;View&gt&semi;&NewLine; &lt&semi;&sol;TouchableOpacity&gt&semi;&NewLine;&rpar;&semi;&NewLine;&NewLine;const styles &equals; StyleSheet&period;create&lpar;&lbrace;&NewLine; listItem&colon; &lbrace;&NewLine; width&colon; "100&percnt;"&comma;&NewLine; marginBottom&colon; 5&comma;&NewLine; padding&colon; 10&comma;&NewLine; backgroundColor&colon; "&num;eee"&comma;&NewLine; flexDirection&colon; "row"&comma;&NewLine; alignItems&colon; "center"&NewLine; &rcub;&comma;&NewLine; movieImage&colon; &lbrace;&NewLine; marginRight&colon; 8&comma;&NewLine; height&colon; 30&comma;&NewLine; width&colon; 30&NewLine; &rcub;&NewLine;&rcub;&rpar;&semi;&NewLine;&NewLine;export default listItem&semi;<&sol;code><&sol;pre>&NewLine;&NewLine;

Exit mobile version