react-native-navigation的迁移库

OptionsScreen.js 8.3KB

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