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

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

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

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

4
   View,
4
   View,
5
   TouchableOpacity,
5
   TouchableOpacity,
6
   Text,
6
   Text,
7
-  Image
7
+  Platform
8
 } from 'react-native';
8
 } from 'react-native';
9
 
9
 
10
-
11
-export default class CustomNavBar extends Component {
10
+export default class CustomTopBar extends Component {
12
 
11
 
13
   constructor(props) {
12
   constructor(props) {
14
     super(props);
13
     super(props);
19
     return (
18
     return (
20
       <View style={styles.container}>
19
       <View style={styles.container}>
21
         <TouchableOpacity stye={styles.button} onPress={ () => alert('Thanks for that :)') }>
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
         </TouchableOpacity>
22
         </TouchableOpacity>
25
 
23
 
26
       </View>
24
       </View>
32
   container: {
30
   container: {
33
     flex: 1,
31
     flex: 1,
34
     justifyContent: 'center',
32
     justifyContent: 'center',
35
-    alignItems: 'center',
36
-    backgroundColor: 'transparent'
33
+    alignItems: 'center'
37
   },
34
   },
38
   button: {
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

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
+});