Skip to content

Commit

Permalink
chore: migrate codegen to TypeScript (#1600)
Browse files Browse the repository at this point in the history
## Description

Issues

* [x] ~~`activityState` is set to `0.0` by default in codegened files
despite being explicitly set to `WithDefault<Float, -1.0>` in config (it
should be `-1.0`). Tested it multiple times it looks like you can't set
number < 0 for default when using TypeScript - tested with both `Int32`
and `Float` (with Flow it worked fine).~~
* [x] ~~`yarn lint` fails~~ 
* [x]
~software-mansion/react-native-screens#1631

There are no other differences between codegened files -- I checked it
file by file with diff tool.


Update: It was confirmed by React Native developer that this indeed is a
bug and will be fixed with 0.71.

Update:

* facebook/react-native#34800

was merged and is available is `0.71` rc branches of React Native. 

### ***Important note***

Merging this PR will be breaking change for Fabric support for
`react-native` versions lower than `0.71.0` (`activityState` &
`sheetCornerRadius` will be broken).

## Changes

* Migrated codegen spec files from Flow to TS.
* Also bumped `@types/react-native` to `0.69.6` [(see
explanation)](software-mansion/react-native-screens@d2ed6ec)
* Had to do some minor type-fixing in our types
* Had to patch `react-navigation-stack` types. This dependency is
required for v4.

<!--

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before

### After

-->

## Test code and steps to reproduce

I created a backup of codegened code from before this PR. 
After applying these changes I ran: `./gradlew
:react-native-screens:generateCodegenArtifactsFromSchema` (or just build
application) and then I manually compared codegend files using diff
checker - the output code is the same.

## Checklist

- [x] Ensured that CI passes (there is a known issue with e2e on iOS, it
will be handled separately)
  • Loading branch information
kkafar authored Jan 18, 2023
1 parent 53dd1dc commit 795e4e5
Show file tree
Hide file tree
Showing 26 changed files with 1,417 additions and 1,213 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ module.exports = {
'react-native-screens/createNativeStackNavigator',
'react-native-screens/reanimated',
],
'import/ignore': ['node_modules/react-native/index\\.js$'],
'import/ignore': [
'node_modules/react-native/index\\.js$',
'react-native/Libraries/Utilities/codegenNativeComponent.*',
'react-native/Libraries/Types/CodegenTypes.*'
],
'import/resolver': {
node: {
paths: ['src'],
Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"lint-android": "./android/gradlew -p android spotlessCheck -q",
"lint": "yarn lint-js && yarn lint-android",
"release": "npm login && release-it",
"prepare": "bob build && husky install"
"prepare": "bob build && husky install",
"postinstall": "patch-package"
},
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down Expand Up @@ -71,11 +72,10 @@
"@react-navigation/native": "^5.8.0",
"@react-navigation/stack": "^5.10.0",
"@types/jest": "^26.0.8",
"@types/react": "^16.9.44",
"@types/react-native": "^0.63.2",
"@types/react": "^18.0.24",
"@types/react-test-renderer": "^16.9.2",
"@typescript-eslint/eslint-plugin": "^3.7.1",
"@typescript-eslint/parser": "^3.7.1",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"@react-native-community/cli": "^9.0.0",
"@react-native-community/cli-platform-android": "^9.0.0",
"@react-native-community/cli-platform-ios": "^9.0.0",
Expand All @@ -99,22 +99,24 @@
"lint-staged": "^11.1.2",
"metro-react-native-babel-preset": "^0.61.0",
"prettier": "^2.0.4",
"react": "^16.13.1",
"react": "18.2.0",
"react-dom": "^16.13.1",
"react-native": "^0.63.2",
"react-native": "0.71.0",
"react-native-reanimated": "^2.2.0",
"react-native-safe-area-context": "^4.0.1-rc.5",
"react-native-safe-area-context": "^4.4.1",
"react-native-windows": "^0.64.8",
"react-navigation": "^4.4.3",
"react-navigation-stack": "^2.9.0",
"react-test-renderer": "^16.13.1",
"release-it": "^13.5.2",
"typescript": "^3.9.7"
"patch-package": "6.5.1",
"typescript": "4.8.4"
},
"resolutions": {
"@react-native-community/cli-platform-android": "^9.0.0",
"@react-native-community/cli": "^9.0.0",
"@react-native-community/cli-platform-ios": "^9.0.0"
"@react-native-community/cli-platform-ios": "^9.0.0",
"@types/react": "^18.0.24"
},
"lint-staged": {
"{src,Example}/**/*.{js,ts,tsx}": "yarn format-js",
Expand Down
80 changes: 80 additions & 0 deletions patches/react-navigation-stack+2.10.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
diff --git a/node_modules/react-navigation-stack/src/vendor/types.tsx b/node_modules/react-navigation-stack/src/vendor/types.tsx
index 977e7d4..50cdd8e 100644
--- a/node_modules/react-navigation-stack/src/vendor/types.tsx
+++ b/node_modules/react-navigation-stack/src/vendor/types.tsx
@@ -104,17 +104,17 @@ export type Scene<T> = {
/**
* Progress value of the current screen.
*/
- current: Animated.AnimatedInterpolation;
+ current: Animated.AnimatedInterpolation<number>;
/**
* Progress value for the screen after this one in the stack.
* This can be `undefined` in case the screen animating is the last one.
*/
- next?: Animated.AnimatedInterpolation;
+ next?: Animated.AnimatedInterpolation<number>;
/**
* Progress value for the screen before this one in the stack.
* This can be `undefined` in case the screen animating is the first one.
*/
- previous?: Animated.AnimatedInterpolation;
+ previous?: Animated.AnimatedInterpolation<number>;
};
};

@@ -509,7 +509,7 @@ export type StackCardInterpolationProps = {
/**
* Animated node representing the progress value of the current screen.
*/
- progress: Animated.AnimatedInterpolation;
+ progress: Animated.AnimatedInterpolation<number>;
};
/**
* Values for the current screen the screen after this one in the stack.
@@ -519,7 +519,7 @@ export type StackCardInterpolationProps = {
/**
* Animated node representing the progress value of the next screen.
*/
- progress: Animated.AnimatedInterpolation;
+ progress: Animated.AnimatedInterpolation<number>;
};
/**
* The index of the card in the stack.
@@ -528,15 +528,15 @@ export type StackCardInterpolationProps = {
/**
* Animated node representing whether the card is closing (1 - closing, 0 - not closing).
*/
- closing: Animated.AnimatedInterpolation;
+ closing: Animated.AnimatedInterpolation<number>;
/**
* Animated node representing whether the card is being swiped (1 - swiping, 0 - not swiping).
*/
- swiping: Animated.AnimatedInterpolation;
+ swiping: Animated.AnimatedInterpolation<number>;
/**
* Animated node representing multiplier when direction is inverted (-1 - inverted, 1 - normal).
*/
- inverted: Animated.AnimatedInterpolation;
+ inverted: Animated.AnimatedInterpolation<number>;
/**
* Layout measurements for various items we use for animation.
*/
@@ -588,7 +588,7 @@ export type StackHeaderInterpolationProps = {
/**
* Animated node representing the progress value of the current screen.
*/
- progress: Animated.AnimatedInterpolation;
+ progress: Animated.AnimatedInterpolation<number>;
};
/**
* Values for the current screen the screen after this one in the stack.
@@ -598,7 +598,7 @@ export type StackHeaderInterpolationProps = {
/**
* Animated node representing the progress value of the next screen.
*/
- progress: Animated.AnimatedInterpolation;
+ progress: Animated.AnimatedInterpolation<number>;
};
/**
* Layout measurements for various items we use for animation.
19 changes: 0 additions & 19 deletions src/fabric/FullWindowOverlayNativeComponent.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/fabric/FullWindowOverlayNativeComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import type { ViewProps } from 'react-native';

interface NativeProps extends ViewProps {}

export default codegenNativeComponent<NativeProps>('RNSFullWindowOverlay', {});
19 changes: 0 additions & 19 deletions src/fabric/ScreenContainerNativeComponent.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/fabric/ScreenContainerNativeComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import type { ViewProps } from 'react-native';

interface NativeProps extends ViewProps {}

export default codegenNativeComponent<NativeProps>('RNSScreenContainer', {});
104 changes: 0 additions & 104 deletions src/fabric/ScreenNativeComponent.js

This file was deleted.

Loading

0 comments on commit 795e4e5

Please sign in to comment.