react-native-navigation的迁移库

OptionsScreen.js 8.4KB

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