react-native-navigation的迁移库

OptionsScreen.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, Text, Button } = 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 BUTTON_LEFT = 'buttonLeft';
  9. class OptionsScreen extends Component {
  10. static get options() {
  11. return {
  12. topBar: {
  13. title: 'Static Title',
  14. textColor: 'black',
  15. drawUnder: false,
  16. largeTitle: false,
  17. hidden: false,
  18. textFontSize: 16,
  19. textFontFamily: 'HelveticaNeue-Italic',
  20. testID: testIDs.TOP_BAR_ELEMENT,
  21. rightButtons: [{
  22. id: BUTTON_ONE,
  23. testID: BUTTON_ONE,
  24. title: 'One',
  25. buttonFontSize: 28,
  26. buttonColor: 'red'
  27. }],
  28. leftButtons: [{
  29. id: BUTTON_LEFT,
  30. testID: BUTTON_LEFT,
  31. icon: require('../../img/navicon_add.png'),
  32. title: 'Left',
  33. buttonColor: 'purple'
  34. }]
  35. }
  36. };
  37. }
  38. constructor(props) {
  39. super(props);
  40. this.onClickDynamicOptions = this.onClickDynamicOptions.bind(this);
  41. this.onClickShowTopBar = this.onClickShowTopBar.bind(this);
  42. this.onClickHideTopBar = this.onClickHideTopBar.bind(this);
  43. this.onClickScrollViewScreen = this.onClickScrollViewScreen.bind(this);
  44. this.onClickTopBarTransparent = this.onClickTopBarTransparent.bind(this);
  45. this.onClickTopBarOpaque = this.onClickTopBarOpaque.bind(this);
  46. this.onClickCustomTranstition = this.onClickCustomTranstition.bind(this);
  47. this.onClickShowOverlay = this.onClickShowOverlay.bind(this);
  48. this.onClickPushDefaultOptionsScreen = this.onClickPushDefaultOptionsScreen.bind(this);
  49. }
  50. render() {
  51. return (
  52. <View style={styles.root}>
  53. <Text style={styles.h1} testID={testIDs.OPTIONS_SCREEN_HEADER}>{`Options Screen`}</Text>
  54. <Button title="Dynamic Options" testID={testIDs.DYNAMIC_OPTIONS_BUTTON} onPress={this.onClickDynamicOptions} />
  55. <Button title="Show Top Bar" testID={testIDs.SHOW_TOP_BAR_BUTTON} onPress={this.onClickShowTopBar} />
  56. <Button title="Hide Top Bar" testID={testIDs.HIDE_TOP_BAR_BUTTON} onPress={this.onClickHideTopBar} />
  57. <Button title="Top Bar Transparent" onPress={this.onClickTopBarTransparent} />
  58. <Button title="Top Bar Opaque" onPress={this.onClickTopBarOpaque} />
  59. <Button title="scrollView Screen" testID={testIDs.SCROLLVIEW_SCREEN_BUTTON} onPress={this.onClickScrollViewScreen} />
  60. <Button title="Custom Transition" onPress={this.onClickCustomTranstition} />
  61. <Button title="Show custom alert" testID={testIDs.SHOW_CUSTOM_ALERT_BUTTON} onPress={this.onClickAlert} />
  62. <Button title="Show snackbar" testID={testIDs.SHOW_SNACKBAR_BUTTON} onPress={this.onClickSnackbar} />
  63. <Button title="Show overlay" testID={testIDs.SHOW_OVERLAY_BUTTON} onPress={() => this.onClickShowOverlay(true)} />
  64. <Button title="Show touch through overlay" testID={testIDs.SHOW_TOUCH_THROUGH_OVERLAY_BUTTON} onPress={() => this.onClickShowOverlay(false)} />
  65. <Button title="Push Default Options Screen" testID={testIDs.PUSH_DEFAULT_OPTIONS_BUTTON} onPress={this.onClickPushDefaultOptionsScreen} />
  66. <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
  67. </View>
  68. );
  69. }
  70. onNavigationButtonPressed(id) {
  71. if (id === BUTTON_ONE) {
  72. Navigation.setOptions(this.props.componentId, {
  73. topBar: {
  74. rightButtons: [{
  75. id: BUTTON_TWO,
  76. testID: BUTTON_TWO,
  77. title: 'Two',
  78. icon: require('../../img/navicon_add.png'),
  79. disableIconTint: true,
  80. // disabled: true,
  81. showAsAction: 'ifRoom',
  82. buttonColor: 'green',
  83. buttonFontSize: 28,
  84. buttonFontWeight: '800'
  85. }],
  86. leftButtons: []
  87. }
  88. });
  89. } else if (id === BUTTON_TWO) {
  90. Navigation.setOptions(this.props.componentId, {
  91. topBar: {
  92. rightButtons: [{
  93. id: BUTTON_ONE,
  94. testID: BUTTON_ONE,
  95. title: 'One',
  96. buttonColor: 'red'
  97. }],
  98. leftButtons: [{
  99. id: BUTTON_LEFT,
  100. testID: BUTTON_LEFT,
  101. icon: require('../../img/navicon_add.png'),
  102. title: 'Left',
  103. buttonColor: 'purple'
  104. }]
  105. }
  106. });
  107. } else if (id === BUTTON_LEFT) {
  108. Navigation.pop(this.props.componentId);
  109. }
  110. }
  111. onClickDynamicOptions() {
  112. Navigation.setOptions(this.props.componentId, {
  113. topBar: {
  114. title: 'Dynamic Title',
  115. textColor: '#00FFFF',
  116. largeTitle: false,
  117. buttonColor: 'red',
  118. textFontSize: 20,
  119. textFontFamily: 'HelveticaNeue-CondensedBold'
  120. }
  121. });
  122. }
  123. onClickScrollViewScreen() {
  124. Navigation.push(this.props.componentId, {
  125. component: {
  126. name: 'navigation.playground.ScrollViewScreen'
  127. }
  128. });
  129. }
  130. onClickCustomTranstition() {
  131. Navigation.push(this.props.componentId, {
  132. component: {
  133. name: 'navigation.playground.CustomTransitionOrigin'
  134. }
  135. });
  136. }
  137. onClickTopBarTransparent() {
  138. Navigation.setOptions(this.props.componentId, {
  139. topBar: {
  140. transparent: true
  141. }
  142. });
  143. }
  144. onClickTopBarOpaque() {
  145. Navigation.setOptions(this.props.componentId, {
  146. topBar: {
  147. transparent: false
  148. }
  149. });
  150. }
  151. onClickShowTopBar() {
  152. Navigation.setOptions(this.props.componentId, {
  153. topBar: {
  154. hidden: false,
  155. animateHide: true
  156. }
  157. });
  158. }
  159. onClickHideTopBar() {
  160. Navigation.setOptions(this.props.componentId, {
  161. topBar: {
  162. hidden: true,
  163. animateHide: true
  164. }
  165. });
  166. }
  167. onClickAlert() {
  168. Navigation.showOverlay('custom', 'navigation.playground.CustomDialog');
  169. }
  170. onClickSnackbar() {
  171. Navigation.showOverlay('snackbar', {
  172. text: 'Test!',
  173. // textColor: 'red',
  174. // backgroundColor: 'green',
  175. duration: 'long',
  176. button: {
  177. text: 'Action',
  178. textColor: 'blue'
  179. }
  180. });
  181. }
  182. onClickShowOverlay(interceptTouchOutside) {
  183. Navigation.showOverlay({
  184. component: {
  185. name: 'navigation.playground.CustomDialog',
  186. options: {
  187. overlay: {
  188. interceptTouchOutside
  189. }
  190. }
  191. }
  192. });
  193. }
  194. onClickPushDefaultOptionsScreen() {
  195. Navigation.setDefaultOptions({
  196. topBar: {
  197. hidden: true
  198. }
  199. });
  200. Navigation.push(this.props.componentId, {
  201. component: {
  202. name: 'navigation.playground.PushedScreen'
  203. }
  204. });
  205. }
  206. }
  207. const styles = {
  208. root: {
  209. flexGrow: 1,
  210. justifyContent: 'center',
  211. alignItems: 'center',
  212. backgroundColor: 'white'
  213. },
  214. h1: {
  215. fontSize: 24,
  216. textAlign: 'center',
  217. margin: 10
  218. },
  219. h2: {
  220. fontSize: 12,
  221. textAlign: 'center',
  222. margin: 10
  223. },
  224. footer: {
  225. fontSize: 10,
  226. color: '#888',
  227. marginTop: 10
  228. }
  229. };
  230. module.exports = OptionsScreen;