Skip to content

Commit c15845a

Browse files
authored
chore: update the example app
2 parents e5c4954 + d1c4275 commit c15845a

File tree

11 files changed

+226
-15
lines changed

11 files changed

+226
-15
lines changed

example/.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CODEPUSH_DEPLOYMENT_KEY_ANDROID=
2+
CODEPUSH_DEPLOYMENT_KEY_IOS=

example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,5 @@ android/keystores/debug.keystore
7878
lib/
7979

8080
**/.xcode.env.local
81+
82+
.env

example/android/app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,5 @@ dependencies {
117117
implementation jscFlavor
118118
}
119119
}
120+
121+
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

example/android/app/src/main/java/com/codepushdiffexample/MainApplication.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
1010
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
1111
import com.facebook.react.defaults.DefaultReactNativeHost
1212
import com.facebook.soloader.SoLoader
13+
import com.microsoft.codepush.react.CodePush
1314

1415
class MainApplication : Application(), ReactApplication {
1516

@@ -25,6 +26,10 @@ class MainApplication : Application(), ReactApplication {
2526

2627
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
2728

29+
override fun getJSBundleFile(): String {
30+
return CodePush.getJSBundleFile()
31+
}
32+
2833
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
2934
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
3035
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">CodePushDiffExample</string>
3+
<string moduleConfig="true" name="CodePushDeploymentKey">DeploymentKey</string>
34
</resources>

example/android/settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autoli
55
rootProject.name = 'CodePushDiffExample'
66
include ':app'
77
includeBuild('../node_modules/@react-native/gradle-plugin')
8+
9+
include ':app', ':react-native-code-push'
10+
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')

example/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const root = path.resolve(__dirname, '..')
77
module.exports = getConfig(
88
{
99
presets: ['module:@react-native/babel-preset'],
10+
plugins: [['module:react-native-dotenv']],
1011
},
1112
{ root, pkg }
1213
)

example/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"react": "18.3.1",
1414
"react-native": "0.75.4",
15+
"react-native-code-push": "^9.0.0",
1516
"react-native-code-push-diff": "workspace:*"
1617
},
1718
"devDependencies": {
@@ -25,7 +26,8 @@
2526
"appcenter-cli": "^2.14.0",
2627
"babel-plugin-module-resolver": "^5.0.0",
2728
"pod-install": "^0.1.0",
28-
"react-native-builder-bob": "^0.30.2"
29+
"react-native-builder-bob": "^0.30.2",
30+
"react-native-dotenv": "^3.4.11"
2931
},
3032
"engines": {
3133
"node": ">=18"

example/src/App.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,48 @@
1-
import * as React from 'react'
1+
import React, { useState, useEffect } from 'react'
2+
import CodePush, { type LocalPackage } from 'react-native-code-push'
23

3-
import { StyleSheet, View } from 'react-native'
4+
import { StyleSheet, View, Image, Text, Platform } from 'react-native'
5+
6+
const useGetCodePushVersion = () => {
7+
const [version, setVersion] = useState<LocalPackage | null>(null)
8+
useEffect(() => {
9+
CodePush.getUpdateMetadata().then(setVersion)
10+
}, [])
11+
return version
12+
}
13+
14+
const useInstallCodePushUpdate = () => {
15+
useEffect(() => {
16+
CodePush.sync({
17+
deploymentKey: Platform.select({
18+
ios: process.env.CODEPUSH_DEPLOYMENT_KEY_IOS,
19+
android: process.env.CODEPUSH_DEPLOYMENT_KEY_ANDROID,
20+
}),
21+
installMode: CodePush.InstallMode.IMMEDIATE,
22+
})
23+
}, [])
24+
}
425

526
export default function App() {
6-
return <View style={styles.container} />
27+
useInstallCodePushUpdate()
28+
const version = useGetCodePushVersion()
29+
30+
const imageUri = Image.resolveAssetSource(require('./image.png')).uri
31+
32+
return (
33+
<View style={styles.container}>
34+
<Text>CodePush Version: {version?.label ?? 'N/A'}</Text>
35+
<Text>Image URI: {imageUri}</Text>
36+
<Image source={require('./image.png')} />
37+
</View>
38+
)
739
}
840

941
const styles = StyleSheet.create({
1042
container: {
1143
flex: 1,
44+
padding: 20,
45+
gap: 20,
1246
alignItems: 'center',
1347
justifyContent: 'center',
1448
},

example/src/image.png

12.3 KB
Loading

0 commit comments

Comments
 (0)