react-native-navigation的迁移库

OptionsScreen.js 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, Text, Button, Platform } = require('react-native');
  4. const { Navigation } = require('react-native-navigation');
  5. const testIDs = require('../testIDs');
  6. const BUTTON_ONE = 'buttonOne';
  7. const BUTTON_TWO = 'buttonTwo';
  8. const CUSTOM_BUTTON = 'customButton';
  9. const CUSTOM_BUTTON2 = 'customButton2';
  10. const BUTTON_LEFT = 'buttonLeft';
  11. const FAB = 'fab';
  12. class OptionsScreen extends Component {
  13. static get options() {
  14. return {
  15. topBar: {
  16. title: {
  17. text: 'Static Title',
  18. color: 'black',
  19. fontSize: 16,
  20. alignment: 'center',
  21. fontFamily: 'HelveticaNeue-Italic',
  22. largeTitle: false
  23. },
  24. subtitle: {
  25. text: 'Static Subtitle',
  26. color: 'red',
  27. fontFamily: 'HelveticaNeue-Italic',
  28. alignment: 'center'
  29. },
  30. background: {
  31. component: {
  32. name: 'TopBarBackground',
  33. passProps: {
  34. color: '#bbdefb'
  35. }
  36. }
  37. },
  38. ...Platform.select({
  39. android: { drawBehind: true },
  40. ios: { drawBehind: false, }
  41. }),
  42. visible: true,
  43. testID: testIDs.TOP_BAR_ELEMENT,
  44. rightButtons: [
  45. // {
  46. // id: CUSTOM_BUTTON,
  47. // testID: CUSTOM_BUTTON,
  48. // component: 'CustomTextButton'
  49. // },
  50. {
  51. id: CUSTOM_BUTTON2,
  52. testID: CUSTOM_BUTTON2,
  53. component: {
  54. name: 'CustomRoundedButton'
  55. }
  56. },
  57. {
  58. id: BUTTON_ONE,
  59. testID: BUTTON_ONE,
  60. title: 'One',
  61. fontFamily: 'HelveticaNeue-Italic',
  62. fontSize: 28,
  63. color: 'red'
  64. }
  65. ],
  66. leftButtons: [{
  67. id: BUTTON_LEFT,
  68. testID: BUTTON_LEFT,
  69. icon: require('../../img/navicon_add.png'),
  70. title: 'Left',
  71. color: 'purple'
  72. }]
  73. },
  74. fab: {
  75. id: FAB,
  76. backgroundColor: 'orange',
  77. clickColor: 'orange',
  78. rippleColor: 'red',
  79. alignHorizontally: 'left',
  80. actions: [
  81. {
  82. id: 'fab1',
  83. backgroundColor: 'blue',
  84. clickColor: 'blue',
  85. rippleColor: 'aquamarine',
  86. },
  87. {
  88. id: 'fab2',
  89. backgroundColor: 'blueviolet',
  90. clickColor: 'blueviolet',
  91. size: 'mini',
  92. rippleColor: 'aquamarine',
  93. }
  94. ]
  95. }
  96. };
  97. }
  98. render() {
  99. return (
  100. <View style={styles.root}>
  101. <View style={{width: 2, height: 2, backgroundColor: 'red', alignSelf: 'center'}}/>
  102. <Text style={styles.h1} testID={testIDs.OPTIONS_SCREEN_HEADER}>{`Options Screen`}</Text>
  103. <Button title='Dynamic Options' testID={testIDs.DYNAMIC_OPTIONS_BUTTON} onPress={this.onClickDynamicOptions} />
  104. <Button title='Show Top Bar' testID={testIDs.SHOW_TOP_BAR_BUTTON} onPress={this.onClickShowTopBar} />
  105. <Button title='Hide Top Bar' testID={testIDs.HIDE_TOP_BAR_BUTTON} onPress={this.onClickHideTopBar} />
  106. <Button title='Top Bar Transparent' onPress={this.onClickTopBarTransparent} />
  107. <Button title='Top Bar Opaque' onPress={this.onClickTopBarOpaque} />
  108. <Button title='scrollView Screen' testID={testIDs.SCROLLVIEW_SCREEN_BUTTON} onPress={this.onClickScrollViewScreen} />
  109. <Button title='Custom Transition' testID={testIDs.CUSTOM_TRANSITION_BUTTON} onPress={this.onClickCustomTranstition} />
  110. {Platform.OS === 'android' ? <Button title='Hide fab' testID={testIDs.HIDE_FAB} onPress={this.onClickFab} /> : null}
  111. <Button title='Show overlay' testID={testIDs.SHOW_OVERLAY_BUTTON} onPress={() => this.onClickShowOverlay(true)} />
  112. <Button title='Show touch through overlay' testID={testIDs.SHOW_TOUCH_THROUGH_OVERLAY_BUTTON} onPress={() => this.onClickShowOverlay(false)} />
  113. <Button title='Push Default Options Screen' testID={testIDs.PUSH_DEFAULT_OPTIONS_BUTTON} onPress={this.onClickPushDefaultOptionsScreen} />
  114. <Button title='Show TopBar react view' testID={testIDs.SHOW_TOPBAR_REACT_VIEW} onPress={this.onShowTopBarReactView} />
  115. {Platform.OS === 'android' ? <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onPush} /> : null}
  116. <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
  117. </View>
  118. );
  119. }
  120. onNavigationButtonPressed(id) {
  121. if (id === BUTTON_ONE) {
  122. Navigation.setOptions(this.props.componentId, {
  123. topBar: {
  124. rightButtons: [{
  125. id: BUTTON_TWO,
  126. testID: BUTTON_TWO,
  127. title: 'Two',
  128. icon: require('../../img/navicon_add.png'),
  129. disableIconTint: true,
  130. showAsAction: 'ifRoom',
  131. color: 'green',
  132. fontSize: 28,
  133. fontWeight: '800'
  134. }],
  135. leftButtons: []
  136. }
  137. });
  138. } else if (id === BUTTON_TWO) {
  139. Navigation.setOptions(this.props.componentId, {
  140. topBar: {
  141. rightButtons: [{
  142. id: BUTTON_ONE,
  143. testID: BUTTON_ONE,
  144. title: 'One',
  145. color: 'red'
  146. }],
  147. leftButtons: [{
  148. id: BUTTON_LEFT,
  149. testID: BUTTON_LEFT,
  150. icon: require('../../img/navicon_add.png'),
  151. title: 'Left',
  152. color: 'purple'
  153. }]
  154. }
  155. });
  156. } else if (id === BUTTON_LEFT) {
  157. Navigation.pop(this.props.componentId);
  158. }
  159. }
  160. onClickDynamicOptions = () => {
  161. Navigation.setOptions(this.props.componentId, {
  162. topBar: {
  163. title: {
  164. text: 'Dynamic Title',
  165. color: '#00FFFF',
  166. largeTitle: false,
  167. fontSize: 20,
  168. fontFamily: 'HelveticaNeue-CondensedBold'
  169. },
  170. color: 'red',
  171. }
  172. });
  173. }
  174. onClickScrollViewScreen = () => {
  175. Navigation.push(this.props.componentId, {
  176. component: {
  177. name: 'navigation.playground.ScrollViewScreen'
  178. }
  179. });
  180. }
  181. onClickCustomTranstition = () => {
  182. Navigation.push(this.props.componentId, {
  183. component: {
  184. name: 'navigation.playground.CustomTransitionOrigin'
  185. }
  186. });
  187. }
  188. onClickTopBarTransparent = () => {
  189. Navigation.setOptions(this.props.componentId, {
  190. topBar: {
  191. transparent: true
  192. }
  193. });
  194. }
  195. onClickTopBarOpaque = () => {
  196. Navigation.setOptions(this.props.componentId, {
  197. topBar: {
  198. transparent: false
  199. }
  200. });
  201. }
  202. onClickShowTopBar = () => {
  203. Navigation.setOptions(this.props.componentId, {
  204. topBar: {
  205. visible: true,
  206. animate: true
  207. }
  208. });
  209. }
  210. onClickHideTopBar = () => {
  211. Navigation.setOptions(this.props.componentId, {
  212. topBar: {
  213. visible: false,
  214. animate: true
  215. }
  216. });
  217. }
  218. onClickFab = () => {
  219. Navigation.setOptions(this.props.componentId, {
  220. fab: {
  221. id: FAB,
  222. visible: false
  223. // backgroundColor: 'green'
  224. }
  225. });
  226. }
  227. onClickShowOverlay = (interceptTouchOutside) => {
  228. Navigation.showOverlay({
  229. component: {
  230. name: 'navigation.playground.CustomDialog',
  231. options: {
  232. overlay: {
  233. interceptTouchOutside
  234. }
  235. }
  236. }
  237. });
  238. }
  239. onClickPushDefaultOptionsScreen = () => {
  240. Navigation.setDefaultOptions({
  241. topBar: {
  242. visible: false,
  243. animate: false
  244. }
  245. });
  246. Navigation.push(this.props.componentId, {
  247. component: {
  248. name: 'navigation.playground.PushedScreen'
  249. }
  250. });
  251. }
  252. onShowTopBarReactView = () => {
  253. Navigation.setOptions(this.props.componentId, {
  254. topBar: {
  255. title: {
  256. component: {
  257. name: 'navigation.playground.CustomTopBar',
  258. alignment: 'center'
  259. }
  260. }
  261. }
  262. });
  263. }
  264. onPush = () => {
  265. Navigation.push(this.props.componentId, {
  266. component: {
  267. name: 'navigation.playground.PushedScreen',
  268. options: {
  269. topBar: {
  270. title: {
  271. text: 'pushed'
  272. },
  273. subtitle: {
  274. text: 'subtitle'
  275. }
  276. }
  277. }
  278. }
  279. });
  280. }
  281. }
  282. const styles = {
  283. root: {
  284. flexGrow: 1,
  285. justifyContent: 'center',
  286. alignItems: 'center',
  287. backgroundColor: 'white'
  288. },
  289. h1: {
  290. fontSize: 24,
  291. textAlign: 'center',
  292. margin: 10
  293. },
  294. h2: {
  295. fontSize: 12,
  296. textAlign: 'center',
  297. margin: 10
  298. },
  299. footer: {
  300. fontSize: 10,
  301. color: '#888',
  302. marginTop: 10
  303. }
  304. };
  305. module.exports = OptionsScreen;