mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	Fix example metro config
This commit is contained in:
		| @@ -2,10 +2,9 @@ const path = require('path'); | |||||||
|  |  | ||||||
| const extraNodeModules = { | const extraNodeModules = { | ||||||
|   'react-native': path.resolve(__dirname, 'node_modules/react-native'), |   'react-native': path.resolve(__dirname, 'node_modules/react-native'), | ||||||
|  |   'react-native-update': path.resolve(__dirname, '../..'), | ||||||
|  |   '@babel/runtime': path.resolve(__dirname, 'node_modules/@babel/runtime'), | ||||||
| }; | }; | ||||||
| const blacklistRegexes = [ |  | ||||||
|   /react-native-update[\/\\]node_modules[\/\\]react-native[\/\\].*/, |  | ||||||
| ]; |  | ||||||
| const watchFolders = [path.resolve(__dirname, '../..')]; | const watchFolders = [path.resolve(__dirname, '../..')]; | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
| @@ -19,9 +18,6 @@ module.exports = { | |||||||
|   }, |   }, | ||||||
|   resolver: { |   resolver: { | ||||||
|     extraNodeModules, |     extraNodeModules, | ||||||
|     blacklistRE: require('metro-config/src/defaults/blacklist')( |  | ||||||
|       blacklistRegexes, |  | ||||||
|     ), |  | ||||||
|   }, |   }, | ||||||
|   watchFolders, |   watchFolders, | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| import React, { | import React, {Component} from 'react'; | ||||||
|   Component, | import { | ||||||
|   StyleSheet, |   StyleSheet, | ||||||
|   Platform, |   Platform, | ||||||
|   Text, |   Text, | ||||||
| @@ -26,26 +26,52 @@ import _updateConfig from '../update.json'; | |||||||
| const {appKey} = _updateConfig[Platform.OS]; | const {appKey} = _updateConfig[Platform.OS]; | ||||||
|  |  | ||||||
| export default class App extends Component { | export default class App extends Component { | ||||||
|   componentDidMount(){ |   componentDidMount() { | ||||||
|     if (isRolledBack) { |     if (isRolledBack) { | ||||||
|       Alert.alert('提示', '刚刚更新失败了,版本被回滚.'); |       Alert.alert('提示', '刚刚更新失败了,版本被回滚.'); | ||||||
|     } else if (isFirstTime) { |     } else if (isFirstTime) { | ||||||
|       Alert.alert('提示', '这是当前版本第一次启动,是否要模拟启动失败?将回滚到上一版本', [ |       Alert.alert( | ||||||
|         {text: '是', onPress: ()=>{throw new Error('模拟启动失败,请重启应用')}}, |         '提示', | ||||||
|         {text: '否', onPress: ()=>{markSuccess()}}, |         '这是当前版本第一次启动,是否要模拟启动失败?将回滚到上一版本', | ||||||
|       ]); |         [ | ||||||
|     }; |           { | ||||||
|  |             text: '是', | ||||||
|  |             onPress: () => { | ||||||
|  |               throw new Error('模拟启动失败,请重启应用'); | ||||||
|  |             }, | ||||||
|  |           }, | ||||||
|  |           { | ||||||
|  |             text: '否', | ||||||
|  |             onPress: () => { | ||||||
|  |               markSuccess(); | ||||||
|  |             }, | ||||||
|  |           }, | ||||||
|  |         ], | ||||||
|  |       ); | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|   doUpdate = info => { |   doUpdate = info => { | ||||||
|     downloadUpdate(info).then(hash => { |     downloadUpdate(info) | ||||||
|       Alert.alert('提示', '下载完毕,是否重启应用?', [ |       .then(hash => { | ||||||
|         {text: '是', onPress: ()=>{switchVersion(hash);}}, |         Alert.alert('提示', '下载完毕,是否重启应用?', [ | ||||||
|         {text: '否',}, |           { | ||||||
|         {text: '下次启动时', onPress: ()=>{switchVersionLater(hash);}}, |             text: '是', | ||||||
|       ]); |             onPress: () => { | ||||||
|     }).catch(err => { |               switchVersion(hash); | ||||||
|       Alert.alert('提示', '更新失败.'); |             }, | ||||||
|     }); |           }, | ||||||
|  |           {text: '否'}, | ||||||
|  |           { | ||||||
|  |             text: '下次启动时', | ||||||
|  |             onPress: () => { | ||||||
|  |               switchVersionLater(hash); | ||||||
|  |             }, | ||||||
|  |           }, | ||||||
|  |         ]); | ||||||
|  |       }) | ||||||
|  |       .catch(err => { | ||||||
|  |         Alert.alert('提示', '更新失败.'); | ||||||
|  |       }); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   checkUpdate = () => { |   checkUpdate = () => { | ||||||
| @@ -53,44 +79,58 @@ export default class App extends Component { | |||||||
|       // 开发模式不支持热更新,跳过检查 |       // 开发模式不支持热更新,跳过检查 | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     checkUpdate(appKey).then(info => { |     checkUpdate(appKey) | ||||||
|       if (info.expired) { |       .then(info => { | ||||||
|         Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [ |         if (info.expired) { | ||||||
|           {text: '确定', onPress: ()=>{info.downloadUrl && Linking.openURL(info.downloadUrl)}}, |           Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [ | ||||||
|         ]); |             { | ||||||
|       } else if (info.upToDate) { |               text: '确定', | ||||||
|         Alert.alert('提示', '您的应用版本已是最新.'); |               onPress: () => { | ||||||
|       } else { |                 info.downloadUrl && Linking.openURL(info.downloadUrl); | ||||||
|         Alert.alert('提示', '检查到新的版本'+info.name+',是否下载?\n'+ info.description, [ |               }, | ||||||
|           {text: '是', onPress: ()=>{this.doUpdate(info)}}, |             }, | ||||||
|           {text: '否',}, |           ]); | ||||||
|         ]); |         } else if (info.upToDate) { | ||||||
|       } |           Alert.alert('提示', '您的应用版本已是最新.'); | ||||||
|     }).catch(err => { |         } else { | ||||||
|       console.warn(err); |           Alert.alert( | ||||||
|     }); |             '提示', | ||||||
|  |             '检查到新的版本' + info.name + ',是否下载?\n' + info.description, | ||||||
|  |             [ | ||||||
|  |               { | ||||||
|  |                 text: '是', | ||||||
|  |                 onPress: () => { | ||||||
|  |                   this.doUpdate(info); | ||||||
|  |                 }, | ||||||
|  |               }, | ||||||
|  |               {text: '否'}, | ||||||
|  |             ], | ||||||
|  |           ); | ||||||
|  |         } | ||||||
|  |       }) | ||||||
|  |       .catch(err => { | ||||||
|  |         console.warn(err); | ||||||
|  |       }); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   render() { |   render() { | ||||||
|     return ( |     return ( | ||||||
|       <View style={styles.container}> |       <View style={styles.container}> | ||||||
|         <Text style={styles.welcome}> |         <Text style={styles.welcome}>欢迎使用热更新服务</Text> | ||||||
|           欢迎使用热更新服务 |  | ||||||
|         </Text> |  | ||||||
|         <Image |         <Image | ||||||
|           resizeMode = {'contain'} |           resizeMode={'contain'} | ||||||
|           source = {require('./assets/shoucang.png')} |           source={require('./assets/shoucang.png')} | ||||||
|           style = {styles.image} |           style={styles.image} | ||||||
|         /> |         /> | ||||||
|         <Text style={styles.instructions}> |         <Text style={styles.instructions}> | ||||||
|           这是版本一 {'\n'} |           这是版本一 {'\n'} | ||||||
|           当前包版本号: {packageVersion}{'\n'} |           当前包版本号: {packageVersion} | ||||||
|           当前版本Hash: {currentVersion||'(空)'}{'\n'} |           {'\n'} | ||||||
|  |           当前版本Hash: {currentVersion || '(空)'} | ||||||
|  |           {'\n'} | ||||||
|         </Text> |         </Text> | ||||||
|         <TouchableOpacity onPress={this.checkUpdate}> |         <TouchableOpacity onPress={this.checkUpdate}> | ||||||
|           <Text style={styles.instructions}> |           <Text style={styles.instructions}>点击这里检查更新</Text> | ||||||
|             点击这里检查更新 |  | ||||||
|           </Text> |  | ||||||
|         </TouchableOpacity> |         </TouchableOpacity> | ||||||
|       </View> |       </View> | ||||||
|     ); |     ); | ||||||
| @@ -114,7 +154,5 @@ const styles = StyleSheet.create({ | |||||||
|     color: '#333333', |     color: '#333333', | ||||||
|     marginBottom: 5, |     marginBottom: 5, | ||||||
|   }, |   }, | ||||||
|   image : { |   image: {}, | ||||||
|   }, |  | ||||||
| }); | }); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm