Launch.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * 开屏页面
  3. * @邠心vbe on 2021/03/22
  4. */
  5. import React from 'react'
  6. import { Animated, Easing, Image, StyleSheet, View } from 'react-native'
  7. import {InitSomething} from '../components/Dialog';
  8. import MyStatusBar from '../components/MyStatusBar';
  9. import { PageList } from './Router';
  10. import analytics from '@react-native-firebase/analytics';
  11. class Launch extends React.Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. isShow: true,
  16. opacity: new Animated.Value(0)
  17. };
  18. }
  19. componentDidMount() {
  20. this.init();
  21. //MyStatusBar.setStatusBarThemes(MyStatusBar.DARK_STYLE, colorLight);
  22. InitSomething();
  23. if (isIOS) {
  24. this.goHome(100);
  25. } else {
  26. this.goHome(2500);
  27. }
  28. }
  29. init() {
  30. analytics().logAppOpen();
  31. Animated.timing(this.state.opacity, {
  32. toValue: 1,
  33. duration: 1500,
  34. easing: Easing.linear,
  35. useNativeDriver: true
  36. }).start(() => {
  37. });
  38. }
  39. goHome(time) {
  40. setTimeout(() => {
  41. this.setState({
  42. isShow: false
  43. }, () => {
  44. // 确保状态更新完成后再导航
  45. startPage(PageList.home);
  46. });
  47. }, time);
  48. }
  49. render() {
  50. return (
  51. this.state.isShow
  52. ? isIOS
  53. ? <View style={styles.iosContent}></View>
  54. : <View style={styles.container}>
  55. <Animated.View style={[styles.content, {opacity: this.state.opacity}]}>
  56. <Image
  57. style={styles.logo}
  58. resizeMode='contain'
  59. source={require('../images/app-logo.png')}/>
  60. {/* <Text style={styles.slogan}>Feel The Green Energy</Text> */}
  61. </Animated.View>
  62. </View>
  63. : <View style={styles.loaded}></View>
  64. );
  65. }
  66. }
  67. export default Launch
  68. const styles = StyleSheet.create({
  69. container: {
  70. alignItems: 'center',
  71. backgroundColor: colorLight,
  72. ...StyleSheet.absoluteFillObject
  73. },
  74. iosContent: {
  75. flex: 1,
  76. backgroundColor: colorLight
  77. },
  78. loaded: {
  79. flex: 1,
  80. backgroundColor: '#eee'
  81. },
  82. content: {
  83. alignItems: 'center',
  84. paddingTop: $vh(30)
  85. },
  86. logo: {
  87. width: 240,
  88. height: 120,
  89. marginLeft: 0,
  90. //top: $vh(25),
  91. //bottom: $vh(25),
  92. //position: 'absolute'
  93. },
  94. slogan: {
  95. color: textPrimary,
  96. fontSize: 14,
  97. fontStyle: 'italic',
  98. fontWeight: 'bold'
  99. }
  100. });