Browse Source

Add custom component in TopBar example screen

Guy Carmeli 7 years ago
parent
commit
e73c8efafc

+ 0
- 45
example/src/screens/CustomNavBarScreen.js View File

@@ -1,45 +0,0 @@
1
-import React, {Component} from 'react';
2
-import {
3
-  Text,
4
-  View,
5
-  ScrollView,
6
-  TouchableOpacity,
7
-  StyleSheet,
8
-  Button
9
-} from 'react-native';
10
-
11
-export default class CustomNavBarScreen extends Component {
12
-  static navigatorStyle = {
13
-    drawUnderTabBar: true,
14
-    navBarCustomView: 'example.CustomNavBar',
15
-    navBarCustomViewInitialProps: {name: 'Hi Custom'}
16
-  };
17
-
18
-
19
-  constructor(props) {
20
-    super(props);
21
-  }
22
-
23
-  render() {
24
-    return (
25
-      <View style={styles.container}>
26
-      </View>
27
-    );
28
-  }
29
-
30
-}
31
-
32
-const styles = StyleSheet.create({
33
-  container: {
34
-    flex: 1,
35
-    padding: 20,
36
-    backgroundColor: 'white'
37
-  },
38
-  button: {
39
-    textAlign: 'center',
40
-    fontSize: 18,
41
-    marginBottom: 10,
42
-    marginTop: 10,
43
-    color: 'blue'
44
-  }
45
-});

+ 8
- 1
example/src/screens/Types.js View File

@@ -1,5 +1,5 @@
1 1
 import React from 'react';
2
-import {StyleSheet, View, Text, ScrollView, TouchableHighlight} from 'react-native';
2
+import {StyleSheet, ScrollView} from 'react-native';
3 3
 import Row from '../components/Row';
4 4
 
5 5
 class Types extends React.Component {
@@ -18,6 +18,12 @@ class Types extends React.Component {
18 18
     });
19 19
   };
20 20
 
21
+  pushCustomTopBarScreen = () => {
22
+    this.props.navigator.push({
23
+      screen: 'example.Types.CustomTopBarScreen'
24
+    });
25
+  };
26
+
21 27
   pushTopTabsScreen = () => {
22 28
     this.props.navigator.push({
23 29
       screen: 'example.Types.TopTabs',
@@ -70,6 +76,7 @@ class Types extends React.Component {
70 76
       <ScrollView style={styles.container}>
71 77
         <Row title={'Toggle Drawer'} onPress={this.toggleDrawer}/>
72 78
         <Row title={'Push Screen'} testID={'pushScreen'} onPress={this.pushScreen}/>
79
+        <Row title={'Custom TopBar'} onPress={this.pushCustomTopBarScreen}/>
73 80
         <Row title={'Top Tabs Screen'} onPress={this.pushTopTabsScreen} platform={'android'}/>
74 81
         <Row title={'Show Modal'} onPress={this.showModal}/>
75 82
         <Row title={'Show Lightbox'} onPress={this.showLightBox}/>

+ 2
- 0
example/src/screens/index.js View File

@@ -9,6 +9,7 @@ import Drawer from './types/Drawer';
9 9
 import LightBox from './types/LightBox';
10 10
 import Notification from './types/Notification';
11 11
 import Modal from './types/Modal';
12
+import CustomTopBarScreen from './types/CustomTopBarScreen';
12 13
 import TopTabs from './types/TopTabs';
13 14
 import TabOne from './types/tabs/TabOne';
14 15
 import TabTwo from './types/tabs/TabTwo';
@@ -33,6 +34,7 @@ export default function () {
33 34
   Navigation.registerComponent('example.Types.Modal', () => Modal);
34 35
   Navigation.registerComponent('example.Types.LightBox', () => LightBox);
35 36
   Navigation.registerComponent('example.Types.Notification', () => Notification);
37
+  Navigation.registerComponent('example.Types.CustomTopBarScreen', () => CustomTopBarScreen);
36 38
   Navigation.registerComponent('example.Types.TopTabs', () => TopTabs);
37 39
   Navigation.registerComponent('example.Types.TopTabs.TabOne', () => TabOne);
38 40
   Navigation.registerComponent('example.Types.TopTabs.TabTwo', () => TabTwo);

example/src/screens/CustomNavBar.js → example/src/screens/types/CustomTopBar.js View File

@@ -4,11 +4,10 @@ import {
4 4
   View,
5 5
   TouchableOpacity,
6 6
   Text,
7
-  Image
7
+  Platform
8 8
 } from 'react-native';
9 9
 
10
-
11
-export default class CustomNavBar extends Component {
10
+export default class CustomTopBar extends Component {
12 11
 
13 12
   constructor(props) {
14 13
     super(props);
@@ -19,8 +18,7 @@ export default class CustomNavBar extends Component {
19 18
     return (
20 19
       <View style={styles.container}>
21 20
         <TouchableOpacity stye={styles.button} onPress={ () => alert('Thanks for that :)') }>
22
-          <Text style={{color: 'red', textAlign: 'center'}}>{this.props.name}</Text>
23
-          <Text style={{textAlign: 'center'}}>Press Me</Text>
21
+          <Text style={styles.text}>Press Me</Text>
24 22
         </TouchableOpacity>
25 23
 
26 24
       </View>
@@ -32,16 +30,15 @@ const styles = StyleSheet.create({
32 30
   container: {
33 31
     flex: 1,
34 32
     justifyContent: 'center',
35
-    alignItems: 'center',
36
-    backgroundColor: 'transparent'
33
+    alignItems: 'center'
37 34
   },
38 35
   button: {
39
-    textAlign: 'center',
40
-    fontSize: 22,
41
-    marginBottom: 10,
42
-    marginTop: 10,
43
-    color: 'blue',
44
-
36
+    alignSelf: 'center',
37
+    backgroundColor: 'green'
38
+  },
39
+  text: {
40
+    alignSelf: 'center',
41
+    color: Platform.OS === 'ios' ? 'black' : 'white'
45 42
   }
46 43
 });
47 44
 

+ 39
- 0
example/src/screens/types/CustomTopBarScreen.js View File

@@ -0,0 +1,39 @@
1
+import React, {Component} from 'react';
2
+import {
3
+  View,
4
+  StyleSheet,
5
+  Text
6
+} from 'react-native';
7
+import {Navigation} from 'react-native-navigation';
8
+import CustomTopBar from './CustomTopBar';
9
+Navigation.registerComponent('example.CustomTopBar', () => CustomTopBar);
10
+
11
+export default class CustomTopBarScreen extends Component {
12
+  static navigatorStyle = {
13
+    drawUnderTabBar: true,
14
+    navBarCustomView: 'example.CustomTopBar',
15
+    navBarComponentAlignment: 'center',
16
+    navBarCustomViewInitialProps: {name: 'Hi Custom'}
17
+  };
18
+
19
+  render() {
20
+    return (
21
+      <View style={styles.container}>
22
+        <Text style={styles.text}>Custom component in TopBar</Text>
23
+      </View>
24
+    );
25
+  }
26
+
27
+}
28
+
29
+const styles = StyleSheet.create({
30
+  container: {
31
+    flex: 1,
32
+    alignItems: 'center',
33
+    justifyContent: 'center',
34
+    backgroundColor: 'white'
35
+  },
36
+  text: {
37
+
38
+  }
39
+});