diff --git a/Examples/RN0840/.bundle/config b/Examples/RN0840/.bundle/config new file mode 100644 index 000000000..848943bb5 --- /dev/null +++ b/Examples/RN0840/.bundle/config @@ -0,0 +1,2 @@ +BUNDLE_PATH: "vendor/bundle" +BUNDLE_FORCE_RUBY_PLATFORM: 1 diff --git a/Examples/RN0840/.eslintrc.js b/Examples/RN0840/.eslintrc.js new file mode 100644 index 000000000..187894b6a --- /dev/null +++ b/Examples/RN0840/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: '@react-native', +}; diff --git a/Examples/RN0840/.gitignore b/Examples/RN0840/.gitignore new file mode 100644 index 000000000..de9995595 --- /dev/null +++ b/Examples/RN0840/.gitignore @@ -0,0 +1,75 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +**/.xcode.env.local + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml +*.hprof +.cxx/ +*.keystore +!debug.keystore +.kotlin/ + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/ + +**/fastlane/report.xml +**/fastlane/Preview.html +**/fastlane/screenshots +**/fastlane/test_output + +# Bundle artifact +*.jsbundle + +# Ruby / CocoaPods +**/Pods/ +/vendor/bundle/ + +# Temporary files created by Metro to check the health of the file watcher +.metro-health-check* + +# testing +/coverage + +# Yarn +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions diff --git a/Examples/RN0840/.prettierrc.js b/Examples/RN0840/.prettierrc.js new file mode 100644 index 000000000..06860c8d1 --- /dev/null +++ b/Examples/RN0840/.prettierrc.js @@ -0,0 +1,5 @@ +module.exports = { + arrowParens: 'avoid', + singleQuote: true, + trailingComma: 'all', +}; diff --git a/Examples/RN0840/.watchmanconfig b/Examples/RN0840/.watchmanconfig new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/Examples/RN0840/.watchmanconfig @@ -0,0 +1 @@ +{} diff --git a/Examples/RN0840/App.tsx b/Examples/RN0840/App.tsx new file mode 100644 index 000000000..d65b485bc --- /dev/null +++ b/Examples/RN0840/App.tsx @@ -0,0 +1,188 @@ +import React, { useCallback, useState } from 'react'; +import { + Button, + Platform, + ScrollView, + StatusBar, + Text, + TextInput, + View, +} from 'react-native'; +import CodePush, { + ReleaseHistoryInterface, + UpdateCheckRequest, +} from '@bravemobile/react-native-code-push'; +import axios from 'axios'; +import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'; + +// Set this to true before run `npx code-push release` to release a new bundle +const IS_RELEASING_BUNDLE = false; + +const REACT_NATIVE_VERSION = (() => { + const { major, minor, patch, prerelease } = Platform.constants.reactNativeVersion; + return `${major}.${minor}.${patch}` + (prerelease ? `-${prerelease}` : ''); +})(); + +function App() { + const { top } = useSafeAreaInsets(); + const [syncResult, setSyncResult] = useState(''); + const [progress, setProgress] = useState(0); + const [runningMetadata, setRunningMetadata] = useState(''); + const [pendingMetadata, setPendingMetadata] = useState(''); + const [latestMetadata, setLatestMetadata] = useState(''); + + const handleSync = useCallback(() => { + CodePush.sync( + {}, + status => { + setSyncResult(findKeyByValue(CodePush.SyncStatus, status) ?? ''); + }, + ({ receivedBytes, totalBytes }) => { + setProgress(Math.round((receivedBytes / totalBytes) * 100)); + }, + mismatch => { + console.log('CodePush mismatch', JSON.stringify(mismatch, null, 2)); + }, + ).catch(error => { + console.error(error); + console.log('Sync failed', error.message ?? 'Unknown error'); + }); + }, []); + + const handleMetadata = useCallback(async () => { + const [running, pending, latest] = await Promise.all([ + CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING), + CodePush.getUpdateMetadata(CodePush.UpdateState.PENDING), + CodePush.getUpdateMetadata(CodePush.UpdateState.LATEST), + ]); + setRunningMetadata(JSON.stringify(running ?? null, null, 2)); + setPendingMetadata(JSON.stringify(pending ?? null, null, 2)); + setLatestMetadata(JSON.stringify(latest ?? null, null, 2)); + }, []); + + return ( + + + {`React Native ${REACT_NATIVE_VERSION}`} + + {IS_RELEASING_BUNDLE && + {'UPDATED!'} + } + + + +