瀏覽代碼

styling docs

yogevbd 6 年之前
父節點
當前提交
be09d8a246
共有 2 個文件被更改,包括 162 次插入0 次删除
  1. 1
    0
      docs/_sidebar.md
  2. 161
    0
      docs/docs/styling.md

+ 1
- 0
docs/_sidebar.md 查看文件

@@ -6,6 +6,7 @@
6 6
   - [Top Level](/docs/top-level-api)
7 7
   - [Screen](/docs/screen-api)
8 8
   - [Layout types](/docs/layout-types)
9
+  - [Styling](/docs/styling)
9 10
 - [Migration from v1](/api/README)
10 11
   - [Top Level](/docs/top-level-api-migration)
11 12
   

+ 161
- 0
docs/docs/styling.md 查看文件

@@ -0,0 +1,161 @@
1
+# Styling Options
2
+
3
+You can style the navigator appearance and behavior by passing an `options` object. This object can be passed when the screen is originally created; can be defined per-screen by setting `static get options()` on the screen component; and can be overridden when a screen is pushed.
4
+
5
+The easiest way to style your screen is by adding `static get options()` to your screen React component definition.
6
+
7
+```js
8
+export default class StyledScreen extends Component {
9
+  static get options() {
10
+    return {
11
+      topBar: {
12
+        title: {
13
+          largeTitle: false,
14
+          title: 'My Screen'
15
+        },
16
+        drawBehind: true,
17
+        visible: false,
18
+        animate: false
19
+      }
20
+    };
21
+  }
22
+  
23
+  constructor(props) {
24
+    super(props);
25
+  }
26
+  render() {
27
+    return (
28
+      <View style={{flex: 1}}>...</View>
29
+     );
30
+  }
31
+```
32
+
33
+## Enabling persistent styling properties on iOS
34
+In v2 we added `setDefaultOptions` API for styles that should be applied on all components.
35
+
36
+```js
37
+Navigation.setDefaultOptions({
38
+  topBar: {
39
+    visible: false
40
+  }
41
+});
42
+```
43
+
44
+## Setting styles dynamically
45
+Use the `setOptions` method to change a screen's style dynamically.
46
+
47
+```js
48
+Navigation.setOptions(this.props.componentId, {
49
+  topBar: {
50
+    visible: true
51
+  }
52
+});
53
+```
54
+
55
+## Options object format
56
+
57
+```js
58
+{
59
+  statusBarHidden: false,
60
+  screenBackgroundColor: 'white',
61
+  orientation: ['portrait', 'landscape'],
62
+  statusBarBlur: true,
63
+  statusBarHideWithTopBar: false,
64
+  statusBarStyle: 'light',
65
+  popGesture: true,
66
+  backgroundImage: require('background.png'),
67
+  rootBackgroundImage: require('rootBackground.png'),
68
+  topBar: {
69
+    visible: true,
70
+    leftButtons: [{
71
+      id: 'buttonOne',
72
+      icon: require('icon.png'),
73
+      component: 'example.CustomButtonComponent',
74
+      title: 'Button one',
75
+      enabled: true,
76
+      disableIconTint: false,
77
+      tintColor: 'red',
78
+      disabledColor: 'black',
79
+      testID: 'buttonOneTestID'
80
+    }],
81
+    rightButtons: [],
82
+    hideOnScroll: true,
83
+    buttonColor: 'black',
84
+    translucent: true,
85
+    transparent: false,
86
+    drawBehind: false,
87
+    noBorder: false,
88
+    blur: false,
89
+    animate: false,
90
+    largeTitle: false,
91
+    testID: 'topBar',
92
+    backButtonImage: require('icon.png'),
93
+    backButtonHidden: false,
94
+    backButtonTitle: 'Back',
95
+    hideBackButtonTitle: false,
96
+    componentName: 'example.CustomTopBar',
97
+    title: {
98
+      text: 'Title',
99
+      fontSize: 14,
100
+      color: 'red',
101
+      fontFamily: 'Halvetica',
102
+      component: 'example.CustomTopBarTitle',
103
+      componentAlignment: 'center',
104
+    },
105
+    subtitle: {
106
+      text: 'Title',
107
+      fontSize: 14,
108
+      color: 'red',
109
+      fontFamily: 'Halvetica',
110
+      alignment: 'center'
111
+    },
112
+    background: {
113
+      color: '#00ff00',
114
+      component: 'example.CustomTopBarBackground'
115
+    }
116
+  },
117
+  bottomTabs: {
118
+    visible: true,
119
+    animate: false,
120
+    currentTabIndex: 0,
121
+    testID: 'bottomTabsTestID',
122
+    drawBehind: false,
123
+    currentTabId: 'currentTabId',
124
+    translucent: true,
125
+    hideShadow: false,
126
+    backgroundColor: 'white',
127
+    tabColor: 'red',
128
+    selectedTabColor: 'blue',
129
+    fontFamily: 'Halvetica',
130
+    fontSize: 10
131
+  },
132
+  bottomTab: {
133
+    title: 'Tab 1',
134
+    badge: '2',
135
+    testID: 'bottomTabTestID',
136
+    visible: undefined,
137
+    icon: require('tab.png')
138
+  },
139
+  sideMenu: {
140
+    leftSideVisible: false,
141
+    rightSideVisible: false,
142
+    rightSideEnabled: true,
143
+    leftSideEnabled: true
144
+  },
145
+  overlay: {
146
+    interceptTouchOutside: true
147
+  }
148
+}
149
+```
150
+
151
+## Styling the StatusBar
152
+If you set any styles related to the Status Bar, make sure that in Xcode > project > Info.plist, the property `View controller-based status bar appearance` is set to `YES`.
153
+
154
+## Custom fonts
155
+If you'd like to use a custom font, you'll first have to edit your project.
156
+
157
+* Android - add the `.ttf` or `.otf` files to `src/main/assets/fonts/`
158
+
159
+* iOS - follow this [guide](https://medium.com/@dabit3/adding-custom-fonts-to-react-native-b266b41bff7f)
160
+
161
+All supported styles are defined [here](https://github.com/wix/react-native-controllers#styling-navigation). There's also an example project there showcasing all the different styles.