Skip to content

Commit fe1fe9f

Browse files
committed
chore: Add example app for react-native 0.85.3
1 parent 6b7bd84 commit fe1fe9f

59 files changed

Lines changed: 17190 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Examples/RN0853/.bundle/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_PATH: "vendor/bundle"
2+
BUNDLE_FORCE_RUBY_PLATFORM: 1

Examples/RN0853/.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native',
4+
};

Examples/RN0853/.gitignore

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
**/.xcode.env.local
24+
25+
# Android/IntelliJ
26+
#
27+
build/
28+
.idea
29+
.gradle
30+
local.properties
31+
*.iml
32+
*.hprof
33+
.cxx/
34+
*.keystore
35+
!debug.keystore
36+
.kotlin/
37+
38+
# node.js
39+
#
40+
node_modules/
41+
npm-debug.log
42+
yarn-error.log
43+
44+
# fastlane
45+
#
46+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47+
# screenshots whenever they are needed.
48+
# For more information about the recommended setup visit:
49+
# https://docs.fastlane.tools/best-practices/source-control/
50+
51+
**/fastlane/report.xml
52+
**/fastlane/Preview.html
53+
**/fastlane/screenshots
54+
**/fastlane/test_output
55+
56+
# Bundle artifact
57+
*.jsbundle
58+
59+
# Ruby / CocoaPods
60+
**/Pods/
61+
/vendor/bundle/
62+
63+
# Temporary files created by Metro to check the health of the file watcher
64+
.metro-health-check*
65+
66+
# testing
67+
/coverage
68+
69+
# Yarn
70+
.yarn/*
71+
!.yarn/patches
72+
!.yarn/plugins
73+
!.yarn/releases
74+
!.yarn/sdks
75+
!.yarn/versions

Examples/RN0853/.prettierrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
arrowParens: 'avoid',
3+
singleQuote: true,
4+
trailingComma: 'all',
5+
};

Examples/RN0853/.watchmanconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Examples/RN0853/App.tsx

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
import React, { useCallback, useState } from 'react';
2+
import {
3+
Button,
4+
Platform,
5+
ScrollView,
6+
StatusBar,
7+
Text,
8+
TextInput,
9+
View,
10+
} from 'react-native';
11+
import CodePush, {
12+
ReleaseHistoryInterface,
13+
UpdateCheckRequest,
14+
} from '@bravemobile/react-native-code-push';
15+
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
16+
17+
// Set this to true before run `npx code-push release` to release a new bundle
18+
const IS_RELEASING_BUNDLE = false;
19+
20+
const REACT_NATIVE_VERSION = (() => {
21+
const { major, minor, patch, prerelease } = Platform.constants.reactNativeVersion;
22+
return `${major}.${minor}.${patch}` + (prerelease ? `-${prerelease}` : '');
23+
})();
24+
25+
function App() {
26+
const { top } = useSafeAreaInsets();
27+
const [syncResult, setSyncResult] = useState('');
28+
const [progress, setProgress] = useState(0);
29+
const [runningMetadata, setRunningMetadata] = useState('');
30+
const [pendingMetadata, setPendingMetadata] = useState('');
31+
const [latestMetadata, setLatestMetadata] = useState('');
32+
33+
const handleSync = useCallback(() => {
34+
CodePush.sync(
35+
{},
36+
status => {
37+
setSyncResult(findKeyByValue(CodePush.SyncStatus, status) ?? '');
38+
},
39+
({ receivedBytes, totalBytes }) => {
40+
setProgress(Math.round((receivedBytes / totalBytes) * 100));
41+
},
42+
mismatch => {
43+
console.log('CodePush mismatch', JSON.stringify(mismatch, null, 2));
44+
},
45+
).catch(error => {
46+
console.error(error);
47+
console.log('Sync failed', error.message ?? 'Unknown error');
48+
});
49+
}, []);
50+
51+
const handleMetadata = useCallback(async () => {
52+
const [running, pending, latest] = await Promise.all([
53+
CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING),
54+
CodePush.getUpdateMetadata(CodePush.UpdateState.PENDING),
55+
CodePush.getUpdateMetadata(CodePush.UpdateState.LATEST),
56+
]);
57+
setRunningMetadata(JSON.stringify(running ?? null, null, 2));
58+
setPendingMetadata(JSON.stringify(pending ?? null, null, 2));
59+
setLatestMetadata(JSON.stringify(latest ?? null, null, 2));
60+
}, []);
61+
62+
return (
63+
<View style={{ flex: 1, paddingTop: top, backgroundColor: 'white' }}>
64+
<Text style={{ fontSize: 20, fontWeight: '600' }}>
65+
{`React Native ${REACT_NATIVE_VERSION}`}
66+
</Text>
67+
{IS_RELEASING_BUNDLE && <Text style={{ fontSize: 20, fontWeight: '600' }}>
68+
{'UPDATED!'}
69+
</Text>}
70+
71+
<ScrollView contentContainerStyle={{ padding: 16, gap: 16 }}>
72+
<View style={{ gap: 8 }}>
73+
<Button title="Check for updates" onPress={handleSync} />
74+
<Text>{`Result: ${syncResult}`}</Text>
75+
<Text>{`Progress: ${progress > 0 ? `${progress}%` : ''}`}</Text>
76+
</View>
77+
78+
<View style={{ gap: 8 }}>
79+
<Button
80+
title="Clear updates"
81+
onPress={() => {
82+
CodePush.clearUpdates();
83+
setSyncResult('');
84+
setProgress(0);
85+
}}
86+
/>
87+
<Button title="Restart app" onPress={() => CodePush.restartApp()} />
88+
<Button title="Get update metadata" onPress={handleMetadata} />
89+
<Text>{runningMetadata === '' ? 'METADATA_IDLE' : runningMetadata === 'null' ? 'METADATA_NULL' : `METADATA_V${JSON.parse(runningMetadata).label}`}</Text>
90+
<MetadataBlock label="Running" value={runningMetadata} />
91+
<MetadataBlock label="Pending" value={pendingMetadata} />
92+
<MetadataBlock label="Latest" value={latestMetadata} />
93+
</View>
94+
</ScrollView>
95+
</View>
96+
);
97+
}
98+
99+
function MetadataBlock({
100+
label,
101+
value,
102+
}: {
103+
label: string;
104+
value: string | null | undefined;
105+
}) {
106+
return (
107+
<View style={{ gap: 4 }}>
108+
<Text style={{ fontWeight: '600' }}>{label}</Text>
109+
<TextInput
110+
value={String(value)}
111+
multiline
112+
style={{ borderWidth: 1, borderRadius: 4, padding: 8, minHeight: 60, color: 'black' }}
113+
/>
114+
</View>
115+
);
116+
}
117+
118+
const CODEPUSH_HOST = 'PLACEHOLDER';
119+
const IDENTIFIER = 'RN0853';
120+
121+
async function releaseHistoryFetcher(
122+
updateRequest: UpdateCheckRequest,
123+
): Promise<ReleaseHistoryInterface> {
124+
const jsonFileName = `${updateRequest.app_version}.json`;
125+
const releaseHistoryUrl = `${CODEPUSH_HOST}/histories/${getPlatform()}/${IDENTIFIER}/${jsonFileName}`;
126+
127+
try {
128+
const response = await fetch(releaseHistoryUrl, {
129+
method: 'GET',
130+
headers: {
131+
Accept: 'application/json',
132+
'Cache-Control': 'no-cache',
133+
},
134+
});
135+
if (!response.ok) {
136+
throw new Error(`Failed to fetch release history: ${response.status} ${response.statusText}`);
137+
}
138+
return (await response.json()) as ReleaseHistoryInterface;
139+
} catch (error) {
140+
console.error(error);
141+
throw error;
142+
}
143+
}
144+
145+
function WithSafeAreaProvider() {
146+
return (
147+
<SafeAreaProvider>
148+
<StatusBar barStyle="dark-content" />
149+
<App />
150+
</SafeAreaProvider>
151+
);
152+
}
153+
154+
export default CodePush({
155+
checkFrequency: CodePush.CheckFrequency.MANUAL,
156+
releaseHistoryFetcher,
157+
onUpdateSuccess: label => {
158+
console.log('Update success', label);
159+
},
160+
onUpdateRollback: label => {
161+
console.log('Update rolled back', label);
162+
},
163+
onSyncError: (label, error) => {
164+
console.error(error);
165+
console.log('Sync error', label);
166+
},
167+
onDownloadStart: label => {
168+
console.log('Download start', label);
169+
},
170+
onDownloadSuccess: label => {
171+
console.log('Download success', label);
172+
},
173+
})(WithSafeAreaProvider);
174+
175+
function getPlatform() {
176+
switch (Platform.OS) {
177+
case 'ios':
178+
return 'ios';
179+
case 'android':
180+
return 'android';
181+
default:
182+
throw new Error('Unsupported platform');
183+
}
184+
}
185+
186+
function findKeyByValue(
187+
object: Record<string, unknown>,
188+
value: unknown,
189+
) {
190+
return Object.keys(object).find(key => object[key] === value);
191+
}

Examples/RN0853/Gemfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
source 'https://rubygems.org'
2+
3+
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4+
ruby ">= 2.6.10"
5+
6+
# Exclude problematic versions of cocoapods and activesupport that causes build failures.
7+
gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1'
8+
gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0'
9+
gem 'xcodeproj', '< 1.26.0'
10+
gem 'concurrent-ruby', '< 1.3.4'
11+
12+
# Ruby 3.4.0 has removed some libraries from the standard library.
13+
gem 'bigdecimal'
14+
gem 'logger'
15+
gem 'benchmark'
16+
gem 'mutex_m'
17+
gem 'nkf'

0 commit comments

Comments
 (0)