react-native-navigation的迁移库

OptionsScreen.js 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
  135. </View>
  136. );
  137. }
  138. navigationButtonPressed({buttonId}) {
  139. if (buttonId === BUTTON_ONE) {
  140. Navigation.mergeOptions(this.props.componentId, {
  141. topBar: {
  142. rightButtons: [{
  143. id: BUTTON_TWO,
  144. testID: BUTTON_TWO,
  145. text: 'Two',
  146. icon: require('../../img/navicon_add.png'),
  147. disableIconTint: true,
  148. showAsAction: 'ifRoom',
  149. color: 'green',
  150. fontSize: 28,
  151. fontWeight: '800'
  152. }],
  153. leftButtons: []
  154. }
  155. });
  156. } else if (buttonId === BUTTON_TWO) {
  157. Navigation.mergeOptions(this.props.componentId, {
  158. topBar: {
  159. rightButtons: [{
  160. id: BUTTON_ONE,
  161. testID: BUTTON_ONE,
  162. text: 'One',
  163. color: 'red'
  164. }],
  165. leftButtons: [{
  166. id: BUTTON_LEFT,
  167. testID: BUTTON_LEFT,
  168. icon: require('../../img/navicon_add.png'),
  169. text: 'Left',
  170. color: 'purple'
  171. }]
  172. }
  173. });
  174. } else if (buttonId === BUTTON_LEFT) {
  175. Navigation.pop(this.props.componentId);
  176. }
  177. }
  178. onClickDynamicOptions = () => {
  179. Navigation.mergeOptions(this.props.componentId, {
  180. topBar: {
  181. title: {
  182. text: 'Dynamic Title',
  183. color: '#00FFFF',
  184. fontSize: 20,
  185. fontFamily: 'HelveticaNeue-CondensedBold'
  186. },
  187. largeTitle: {
  188. visible: false
  189. }
  190. }
  191. });
  192. }
  193. onClickScrollViewScreen = () => {
  194. Navigation.push(this.props.componentId, {
  195. component: {
  196. name: 'navigation.playground.ScrollViewScreen'
  197. }
  198. });
  199. }
  200. onClickCustomTransition = () => {
  201. Navigation.push(this.props.componentId, {
  202. component: {
  203. name: 'navigation.playground.CustomTransitionOrigin'
  204. }
  205. });
  206. }
  207. onClickTopBarTransparent = () => {
  208. Navigation.mergeOptions(this.props.componentId, {
  209. topBar: {
  210. transparent: true
  211. }
  212. });
  213. }
  214. onClickTopBarOpaque = () => {
  215. Navigation.mergeOptions(this.props.componentId, {
  216. topBar: {
  217. transparent: false
  218. }
  219. });
  220. }
  221. onClickShowTopBar = () => {
  222. Navigation.mergeOptions(this.props.componentId, {
  223. topBar: {
  224. visible: true,
  225. animate: true
  226. }
  227. });
  228. }
  229. onClickHideTopBar = () => {
  230. Navigation.mergeOptions(this.props.componentId, {
  231. topBar: {
  232. visible: false,
  233. animate: true
  234. }
  235. });
  236. }
  237. onClickFab = () => {
  238. Navigation.mergeOptions(this.props.componentId, {
  239. fab: {
  240. id: FAB,
  241. visible: false
  242. // backgroundColor: 'green'
  243. }
  244. });
  245. }
  246. onClickShowOverlay = async (interceptTouchOutside) => {
  247. await Navigation.showOverlay({
  248. component: {
  249. name: 'navigation.playground.CustomDialog',
  250. options: {
  251. overlay: {
  252. interceptTouchOutside
  253. }
  254. }
  255. }
  256. });
  257. }
  258. onClickPushDefaultOptionsScreen = () => {
  259. Navigation.setDefaultOptions({
  260. topBar: {
  261. visible: false,
  262. animate: false
  263. }
  264. });
  265. Navigation.push(this.props.componentId, {
  266. component: {
  267. name: 'navigation.playground.PushedScreen'
  268. }
  269. });
  270. }
  271. onShowTopBarReactView = () => {
  272. Navigation.mergeOptions(this.props.componentId, {
  273. topBar: {
  274. title: {
  275. component: {
  276. name: 'navigation.playground.CustomTopBar',
  277. alignment: 'center'
  278. }
  279. }
  280. }
  281. });
  282. }
  283. onPush = () => {
  284. Navigation.push(this.props.componentId, {
  285. component: {
  286. name: 'navigation.playground.PushedScreen',
  287. options: {
  288. topBar: {
  289. title: {
  290. text: 'pushed'
  291. },
  292. subtitle: {
  293. text: 'subtitle'
  294. }
  295. }
  296. }
  297. }
  298. });
  299. }
  300. }
  301. const styles = {
  302. root: {
  303. flexGrow: 1,
  304. justifyContent: 'center',
  305. alignItems: 'center',
  306. backgroundColor: 'white'
  307. },
  308. h1: {
  309. fontSize: 24,
  310. textAlign: 'center',
  311. margin: 10
  312. },
  313. h2: {
  314. fontSize: 12,
  315. textAlign: 'center',
  316. margin: 10
  317. },
  318. footer: {
  319. fontSize: 10,
  320. color: '#888',
  321. marginTop: 10
  322. }
  323. };
  324. module.exports = OptionsScreen;