Skip to content

Commit b2d330f

Browse files
authored
chore: upgrade native-cli example (#93)
1 parent 9f029dc commit b2d330f

40 files changed

+5074
-3661
lines changed

examples/native-cli/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ local.properties
3333
.cxx/
3434
*.keystore
3535
!debug.keystore
36+
.kotlin/
3637

3738
# node.js
3839
#
@@ -74,4 +75,4 @@ yarn-error.log
7475
!.yarn/versions
7576

7677
# Reassure output directory
77-
.reassure
78+
.reassure

examples/native-cli/.prettierrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
arrowParens: 'avoid',
33
bracketSameLine: true,
4+
bracketSpacing: false,
45
singleQuote: true,
56
trailingComma: 'all',
67
};

examples/native-cli/App.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
*/
77

88
import React from 'react';
9-
import type { PropsWithChildren } from 'react';
9+
import type {PropsWithChildren} from 'react';
1010
import {
11-
SafeAreaView,
1211
ScrollView,
1312
StatusBar,
1413
StyleSheet,
@@ -29,7 +28,7 @@ type SectionProps = PropsWithChildren<{
2928
title: string;
3029
}>;
3130

32-
function Section({ children, title }: SectionProps): React.JSX.Element {
31+
function Section({children, title}: SectionProps): React.JSX.Element {
3332
const isDarkMode = useColorScheme() === 'dark';
3433
return (
3534
<View style={styles.sectionContainer}>
@@ -62,19 +61,32 @@ function App(): React.JSX.Element {
6261
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
6362
};
6463

64+
/*
65+
* To keep the template simple and small we're adding padding to prevent view
66+
* from rendering under the System UI.
67+
* For bigger apps the recommendation is to use `react-native-safe-area-context`:
68+
* https://github.com/AppAndFlow/react-native-safe-area-context
69+
*
70+
* You can read more about it here:
71+
* https://github.com/react-native-community/discussions-and-proposals/discussions/827
72+
*/
73+
const safePadding = '5%';
74+
6575
return (
66-
<SafeAreaView style={backgroundStyle}>
76+
<View style={backgroundStyle}>
6777
<StatusBar
6878
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
6979
backgroundColor={backgroundStyle.backgroundColor}
7080
/>
71-
<ScrollView
72-
contentInsetAdjustmentBehavior="automatic"
73-
style={backgroundStyle}>
74-
<Header />
81+
<ScrollView style={backgroundStyle}>
82+
<View style={{paddingRight: safePadding}}>
83+
<Header />
84+
</View>
7585
<View
7686
style={{
7787
backgroundColor: isDarkMode ? Colors.black : Colors.white,
88+
paddingHorizontal: safePadding,
89+
paddingBottom: safePadding,
7890
}}>
7991
<Section title="Step One">
8092
Edit <Text style={styles.highlight}>App.tsx</Text> to change this
@@ -92,7 +104,7 @@ function App(): React.JSX.Element {
92104
<LearnMoreLinks />
93105
</View>
94106
</ScrollView>
95-
</SafeAreaView>
107+
</View>
96108
);
97109
}
98110

examples/native-cli/Gemfile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ source 'https://rubygems.org'
33
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
44
ruby ">= 2.6.10"
55

6-
# Cocoapods 1.15 introduced a bug which break the build. We will remove the upper
7-
# bound in the template on Cocoapods with next React Native release.
8-
gem 'cocoapods', '>= 1.13', '< 1.15'
9-
gem 'activesupport', '>= 6.1.7.5', '< 7.1.0'
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'

examples/native-cli/Gemfile.lock

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
CFPropertyList (3.0.7)
5+
base64
6+
nkf
7+
rexml
8+
activesupport (6.1.7.10)
9+
concurrent-ruby (~> 1.0, >= 1.0.2)
10+
i18n (>= 1.6, < 2)
11+
minitest (>= 5.1)
12+
tzinfo (~> 2.0)
13+
zeitwerk (~> 2.3)
14+
addressable (2.8.7)
15+
public_suffix (>= 2.0.2, < 7.0)
16+
algoliasearch (1.27.5)
17+
httpclient (~> 2.8, >= 2.8.3)
18+
json (>= 1.5.1)
19+
atomos (0.1.3)
20+
base64 (0.2.0)
21+
benchmark (0.4.0)
22+
bigdecimal (3.1.9)
23+
claide (1.1.0)
24+
cocoapods (1.15.2)
25+
addressable (~> 2.8)
26+
claide (>= 1.0.2, < 2.0)
27+
cocoapods-core (= 1.15.2)
28+
cocoapods-deintegrate (>= 1.0.3, < 2.0)
29+
cocoapods-downloader (>= 2.1, < 3.0)
30+
cocoapods-plugins (>= 1.0.0, < 2.0)
31+
cocoapods-search (>= 1.0.0, < 2.0)
32+
cocoapods-trunk (>= 1.6.0, < 2.0)
33+
cocoapods-try (>= 1.1.0, < 2.0)
34+
colored2 (~> 3.1)
35+
escape (~> 0.0.4)
36+
fourflusher (>= 2.3.0, < 3.0)
37+
gh_inspector (~> 1.0)
38+
molinillo (~> 0.8.0)
39+
nap (~> 1.0)
40+
ruby-macho (>= 2.3.0, < 3.0)
41+
xcodeproj (>= 1.23.0, < 2.0)
42+
cocoapods-core (1.15.2)
43+
activesupport (>= 5.0, < 8)
44+
addressable (~> 2.8)
45+
algoliasearch (~> 1.0)
46+
concurrent-ruby (~> 1.1)
47+
fuzzy_match (~> 2.0.4)
48+
nap (~> 1.0)
49+
netrc (~> 0.11)
50+
public_suffix (~> 4.0)
51+
typhoeus (~> 1.0)
52+
cocoapods-deintegrate (1.0.5)
53+
cocoapods-downloader (2.1)
54+
cocoapods-plugins (1.0.0)
55+
nap
56+
cocoapods-search (1.0.1)
57+
cocoapods-trunk (1.6.0)
58+
nap (>= 0.8, < 2.0)
59+
netrc (~> 0.11)
60+
cocoapods-try (1.2.0)
61+
colored2 (3.1.2)
62+
concurrent-ruby (1.3.3)
63+
escape (0.0.4)
64+
ethon (0.16.0)
65+
ffi (>= 1.15.0)
66+
ffi (1.17.2)
67+
fourflusher (2.3.1)
68+
fuzzy_match (2.0.4)
69+
gh_inspector (1.1.3)
70+
httpclient (2.9.0)
71+
mutex_m
72+
i18n (1.14.7)
73+
concurrent-ruby (~> 1.0)
74+
json (2.7.6)
75+
logger (1.7.0)
76+
minitest (5.25.4)
77+
molinillo (0.8.0)
78+
mutex_m (0.3.0)
79+
nanaimo (0.3.0)
80+
nap (1.1.0)
81+
netrc (0.11.0)
82+
nkf (0.2.0)
83+
public_suffix (4.0.7)
84+
rexml (3.4.1)
85+
ruby-macho (2.5.1)
86+
typhoeus (1.4.1)
87+
ethon (>= 0.9.0)
88+
tzinfo (2.0.6)
89+
concurrent-ruby (~> 1.0)
90+
xcodeproj (1.25.1)
91+
CFPropertyList (>= 2.3.3, < 4.0)
92+
atomos (~> 0.1.3)
93+
claide (>= 1.0.2, < 2.0)
94+
colored2 (~> 3.1)
95+
nanaimo (~> 0.3.0)
96+
rexml (>= 3.3.6, < 4.0)
97+
zeitwerk (2.6.18)
98+
99+
PLATFORMS
100+
ruby
101+
102+
DEPENDENCIES
103+
activesupport (>= 6.1.7.5, != 7.1.0)
104+
benchmark
105+
bigdecimal
106+
cocoapods (>= 1.13, != 1.15.1, != 1.15.0)
107+
concurrent-ruby (< 1.3.4)
108+
logger
109+
mutex_m
110+
xcodeproj (< 1.26.0)
111+
112+
RUBY VERSION
113+
ruby 2.6.10p210
114+
115+
BUNDLED WITH
116+
2.1.4

examples/native-cli/README-orig.md

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,76 @@ This is a new [**React Native**](https://reactnative.dev) project, bootstrapped
22

33
# Getting Started
44

5-
>**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding.
5+
> **Note**: Make sure you have completed the [Set Up Your Environment](https://reactnative.dev/docs/set-up-your-environment) guide before proceeding.
66
7-
## Step 1: Start the Metro Server
7+
## Step 1: Start Metro
88

9-
First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native.
9+
First, you will need to run **Metro**, the JavaScript build tool for React Native.
1010

11-
To start Metro, run the following command from the _root_ of your React Native project:
11+
To start the Metro dev server, run the following command from the root of your React Native project:
1212

13-
```bash
14-
# using npm
13+
```sh
14+
# Using npm
1515
npm start
1616

1717
# OR using Yarn
1818
yarn start
1919
```
2020

21-
## Step 2: Start your Application
21+
## Step 2: Build and run your app
2222

23-
Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app:
23+
With Metro running, open a new terminal window/pane from the root of your React Native project, and use one of the following commands to build and run your Android or iOS app:
2424

25-
### For Android
25+
### Android
2626

27-
```bash
28-
# using npm
27+
```sh
28+
# Using npm
2929
npm run android
3030

3131
# OR using Yarn
3232
yarn android
3333
```
3434

35-
### For iOS
35+
### iOS
3636

37-
```bash
38-
# using npm
37+
For iOS, remember to install CocoaPods dependencies (this only needs to be run on first clone or after updating native deps).
38+
39+
The first time you create a new project, run the Ruby bundler to install CocoaPods itself:
40+
41+
```sh
42+
bundle install
43+
```
44+
45+
Then, and every time you update your native dependencies, run:
46+
47+
```sh
48+
bundle exec pod install
49+
```
50+
51+
For more information, please visit [CocoaPods Getting Started guide](https://guides.cocoapods.org/using/getting-started.html).
52+
53+
```sh
54+
# Using npm
3955
npm run ios
4056

4157
# OR using Yarn
4258
yarn ios
4359
```
4460

45-
If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly.
61+
If everything is set up correctly, you should see your new app running in the Android Emulator, iOS Simulator, or your connected device.
62+
63+
This is one way to run your app — you can also build it directly from Android Studio or Xcode.
4664

47-
This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively.
65+
## Step 3: Modify your app
4866

49-
## Step 3: Modifying your App
67+
Now that you have successfully run the app, let's make changes!
5068

51-
Now that you have successfully run the app, let's modify it.
69+
Open `App.tsx` in your text editor of choice and make some changes. When you save, your app will automatically update and reflect these changes — this is powered by [Fast Refresh](https://reactnative.dev/docs/fast-refresh).
5270

53-
1. Open `App.tsx` in your text editor of choice and edit some lines.
54-
2. For **Android**: Press the <kbd>R</kbd> key twice or select **"Reload"** from the **Developer Menu** (<kbd>Ctrl</kbd> + <kbd>M</kbd> (on Window and Linux) or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> (on macOS)) to see your changes!
71+
When you want to forcefully reload, for example to reset the state of your app, you can perform a full reload:
5572

56-
For **iOS**: Hit <kbd>Cmd ⌘</kbd> + <kbd>R</kbd> in your iOS Simulator to reload the app and see your changes!
73+
- **Android**: Press the <kbd>R</kbd> key twice or select **"Reload"** from the **Dev Menu**, accessed via <kbd>Ctrl</kbd> + <kbd>M</kbd> (Windows/Linux) or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> (macOS).
74+
- **iOS**: Press <kbd>R</kbd> in iOS Simulator.
5775

5876
## Congratulations! :tada:
5977

@@ -62,11 +80,11 @@ You've successfully run and modified your React Native App. :partying_face:
6280
### Now what?
6381

6482
- If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps).
65-
- If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started).
83+
- If you're curious to learn more about React Native, check out the [docs](https://reactnative.dev/docs/getting-started).
6684

6785
# Troubleshooting
6886

69-
If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.
87+
If you're having issues getting the above steps to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.
7088

7189
# Learn More
7290

examples/native-cli/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This example showcases Reassure setup for React Native CLI app.
88
2. Copy `jest.config.js` from this repo for RNTL tests to run
99
3. Install `reassure` and `danger` as `devDependencies`
1010
4. Run `yarn reassure init` to:
11-
* generate `reassure-tests.sh` CI script
12-
* generate `dangerfile.js` config for `danger`
13-
* add `.reasure` entry to `.gitignore`
14-
5. (optional) Add `configure({ testingLibrary: 'react-native' });` to your `jest-setup.js` file
11+
- generate `reassure-tests.sh` CI script
12+
- generate `dangerfile.js` config for `danger`
13+
- add `.reasure` entry to `.gitignore`
14+
5. (optional) Add `configure({ testingLibrary: 'react-native' });` to your `jest-setup.js` file

examples/native-cli/__tests__/App.test.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
* @format
33
*/
44

5-
import 'react-native';
65
import React from 'react';
6+
import ReactTestRenderer from 'react-test-renderer';
77
import App from '../App';
88

9-
// Note: import explicitly to use the types shipped with jest.
10-
import { it } from '@jest/globals';
11-
12-
// Note: test renderer must be required after react-native.
13-
import renderer from 'react-test-renderer';
14-
15-
it('renders correctly', () => {
16-
renderer.create(<App />);
9+
test('renders correctly', async () => {
10+
await ReactTestRenderer.act(() => {
11+
ReactTestRenderer.create(<App />);
12+
});
1713
});

0 commit comments

Comments
 (0)