From 2a3b8e5707d9a18201dcf42c633001bdfd029690 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Mon, 22 Jan 2024 15:55:52 +0800 Subject: [PATCH] feat: update example --- Example/testHotUpdate/metro.config.js | 22 +++++----- Example/testHotUpdate/package.json | 2 +- Example/testHotUpdate/src/index.js | 61 +++++++++++++++------------ Example/testHotUpdate/yarn.lock | 9 ++-- 4 files changed, 53 insertions(+), 41 deletions(-) diff --git a/Example/testHotUpdate/metro.config.js b/Example/testHotUpdate/metro.config.js index caf7ce4..244b36d 100644 --- a/Example/testHotUpdate/metro.config.js +++ b/Example/testHotUpdate/metro.config.js @@ -1,12 +1,12 @@ const path = require('path'); -const extraNodeModules = { - react: path.resolve(__dirname, 'node_modules/react'), - '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 watchFolders = [path.resolve(__dirname, '../..')]; +// const extraNodeModules = { +// react: path.resolve(__dirname, 'node_modules/react'), +// '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 watchFolders = [path.resolve(__dirname, '../..')]; module.exports = { transformer: { @@ -17,8 +17,8 @@ module.exports = { }, }), }, - resolver: { - extraNodeModules, - }, - watchFolders, + // resolver: { + // extraNodeModules, + // }, + // watchFolders, }; diff --git a/Example/testHotUpdate/package.json b/Example/testHotUpdate/package.json index db01693..64f0b34 100644 --- a/Example/testHotUpdate/package.json +++ b/Example/testHotUpdate/package.json @@ -18,7 +18,7 @@ "react-native": "0.69.8", "react-native-paper": "^5.12.1", "react-native-safe-area-context": "^4.8.2", - "react-native-update": "link:../..", + "react-native-update": "10.0.0-beta.1", "react-native-vector-icons": "^10.0.3" }, "devDependencies": { diff --git a/Example/testHotUpdate/src/index.js b/Example/testHotUpdate/src/index.js index 5d31e5b..e61152b 100644 --- a/Example/testHotUpdate/src/index.js +++ b/Example/testHotUpdate/src/index.js @@ -24,9 +24,12 @@ function App() { switchVersionLater, switchVersion, updateInfo, + packageVersion, + currentHash, progress: {received, total} = {}, } = usePushy(); const [useDefaultAlert, setUseDefaultAlert] = useState(true); + const [showTestConsole, setShowTestConsole] = useState(false); const [showUpdateBanner, setShowUpdateBanner] = useState(false); const [showUpdateSnackbar, setShowUpdateSnackbar] = useState(false); const snackbarVisible = @@ -37,16 +40,20 @@ function App() { return ( 欢迎使用Pushy热更新服务 - { - setUseDefaultAlert(v); - client.setOptions({ - showAlert: v, - }); - }}> - {useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示 - + + + {useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示 + + { + setUseDefaultAlert(v); + client.setOptions({ + showAlert: v, + }); + }} + /> + @@ -70,28 +77,30 @@ function App() { testID="testcase" style={{marginTop: 15}} onLongPress={() => { - this.setState({showTestConsole: true}); + setShowTestConsole(true); }}> react-native-update版本:{client.version} - { - setShowUpdateSnackbar(false); - }} - action={{ - label: '更新', - onPress: async () => { + {snackbarVisible && ( + { setShowUpdateSnackbar(false); - await downloadUpdate(); - setShowUpdateBanner(true); - }, - }}> - 有新版本({updateInfo.version})可用,是否更新? - + }} + action={{ + label: '更新', + onPress: async () => { + setShowUpdateSnackbar(false); + await downloadUpdate(); + setShowUpdateBanner(true); + }, + }}> + 有新版本({updateInfo.version})可用,是否更新? + + )}