react-native-navigation的迁移库

OptionsScreen.js 6.3KB

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