react-native-navigation的迁移库

OptionsScreen.js 9.1KB

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