VoucherPage.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * 代金券页面适配器
  3. * @邠心vbe on 2024/04/09
  4. */
  5. import React, { Component } from 'react';
  6. import { StyleSheet } from 'react-native';
  7. import ListPoints from './ListPoints';
  8. import ListVoucher from './ListVoucher';
  9. import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
  10. import app from '../../../app.json';
  11. import { PageList } from '../Router';
  12. export default class VoucherPage extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. pageAdapter: [{
  17. title: $t('voucher.tabPoints'),
  18. name: "Deals",
  19. component: ListPoints
  20. },{
  21. title: $t('voucher.tabVoucher'),
  22. name: "Vouchers",
  23. component: ListVoucher
  24. }]
  25. };
  26. this.tabBarStyle = {
  27. tabBarStyle: styles.tabStyle,
  28. tabBarPressColor: rippleColor,
  29. tabBarScrollEnabled: false,
  30. tabBarIndicatorStyle: styles.indicator,
  31. tabBarActiveTintColor: tabBarTextActive,
  32. tabBarInactiveTintColor: tabBarTextInactive
  33. }
  34. this.isHide = false;
  35. }
  36. backPage() {
  37. if (!this.isHide) {
  38. startPage(PageList.home);
  39. return true;
  40. }
  41. }
  42. render() {
  43. const Tab = createMaterialTopTabNavigator();
  44. return (
  45. <Tab.Navigator
  46. style={styles.container}
  47. screenOptions={{
  48. lazy: false,
  49. lazyPreloadDistance: 1,
  50. ...this.tabBarStyle
  51. }}
  52. backBehavior={() => this.backPage()}>
  53. { this.state.pageAdapter.map((item, index) =>
  54. <Tab.Screen
  55. key={index}
  56. name={item.name}
  57. component={item.component}
  58. options={{
  59. title: item.title,
  60. tabBarAllowFontScaling: false
  61. }}
  62. />
  63. )}
  64. </Tab.Navigator>
  65. );
  66. }
  67. }
  68. const styles = StyleSheet.create({
  69. container: {
  70. flex: 1,
  71. backgroundColor: pageBackground
  72. },
  73. tabStyle: {
  74. backgroundColor: app.isWhitelabel ? colorLight : colorPrimary
  75. },
  76. indicator: {
  77. backgroundColor: app.isWhitelabel ? colorPrimary : colorLight
  78. }
  79. })