Skip to content

Commit ae0f1f9

Browse files
authored
feat(windows): add New Architecture support (#1147)
1 parent bb41ee1 commit ae0f1f9

20 files changed

+1707
-592
lines changed

Diff for: packages/default-storage/example/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ local.properties
3636
/windows/AppPackages
3737
/windows/ExperimentalFeatures.props
3838
/windows/NuGet.Config
39+
/windows/ReactApp.Package
3940

4041
# node.js
4142
#

Diff for: packages/default-storage/example/examples/Functional.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
33
import React, { useEffect, useState } from "react";
44
import isEqual from "lodash/isEqual";
55
import {
6-
NativeModules,
76
Platform,
87
ScrollView,
98
StyleSheet,
109
Text,
10+
TurboModuleRegistry,
1111
View,
1212
} from "react-native";
13+
import type { AsyncStorageTestSupport } from "./types";
1314
import type { TestStep, TestValue } from "./tests";
1415
import tests from "./tests";
1516

@@ -130,7 +131,9 @@ function Functional(): JSX.Element {
130131
})
131132
.then(async () => {
132133
const AsyncStorageTestSupport =
133-
NativeModules["AsyncStorageTestSupport"];
134+
TurboModuleRegistry.get<AsyncStorageTestSupport>(
135+
"AsyncStorageTestSupport"
136+
);
134137

135138
for (const [currentName, test] of Object.entries(tests)) {
136139
const name = currentName + " with delegate";

Diff for: packages/default-storage/example/examples/MergeItem.tsx

+9-17
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
1010
import React, { useCallback, useState } from "react";
1111
import {
1212
Button,
13-
NativeModules,
1413
StyleSheet,
1514
Text,
1615
TextInput,
16+
TurboModuleRegistry,
1717
View,
1818
} from "react-native";
19+
import type { AsyncStorageTestSupport } from "./types";
1920

2021
type Personalia = {
2122
age: string;
@@ -102,6 +103,9 @@ function Merge(): JSX.Element {
102103

103104
const { trait1, trait2 } = traits;
104105

106+
const AsyncStorageTestSupport =
107+
TurboModuleRegistry.get<AsyncStorageTestSupport>("AsyncStorageTestSupport");
108+
105109
return (
106110
<View>
107111
<View>
@@ -174,26 +178,14 @@ function Merge(): JSX.Element {
174178
<Button
175179
testID="setDelegate_button"
176180
title="Set native delegate"
177-
disabled={
178-
!NativeModules["AsyncStorageTestSupport"] ||
179-
!NativeModules["AsyncStorageTestSupport"].test_setDelegate
180-
}
181-
onPress={() =>
182-
NativeModules["AsyncStorageTestSupport"].test_setDelegate(() => {})
183-
}
181+
disabled={!AsyncStorageTestSupport?.test_setDelegate}
182+
onPress={() => AsyncStorageTestSupport?.test_setDelegate(() => {})}
184183
/>
185184
<Button
186185
testID="unsetDelegate_button"
187186
title="Unset native delegate"
188-
disabled={
189-
!NativeModules["AsyncStorageTestSupport"] ||
190-
!NativeModules["AsyncStorageTestSupport"].test_unsetDelegate
191-
}
192-
onPress={() =>
193-
NativeModules["AsyncStorageTestSupport"].test_unsetDelegate(
194-
() => {}
195-
)
196-
}
187+
disabled={!AsyncStorageTestSupport?.test_unsetDelegate}
188+
onPress={() => AsyncStorageTestSupport?.test_unsetDelegate(() => {})}
197189
/>
198190
</View>
199191

Diff for: packages/default-storage/example/examples/types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { TurboModule } from "react-native";
2+
3+
type AsyncStorageDelegate = (value?: boolean) => void;
4+
5+
export type AsyncStorageTestSupport = TurboModule & {
6+
test_setDelegate: (delegate: AsyncStorageDelegate) => void;
7+
test_unsetDelegate: (delegate: AsyncStorageDelegate) => void;
8+
};

Diff for: packages/default-storage/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"start:macos": "react-native run-macos --project-path example/macos --scheme AsyncStorageExample",
4747
"start:web": "expo start --web",
4848
"start:windows": "install-windows-test-app -p example/windows && react-native run-windows --root example --logging --no-packager --no-telemetry",
49+
"start:windows:fabric": "install-windows-test-app -p example/windows --use-fabric && react-native run-windows --root example --logging --no-packager --no-telemetry",
4950
"build:e2e:android": "scripts/android_e2e.sh 'build'",
5051
"build:e2e:ios": "scripts/ios_e2e.sh 'build'",
5152
"build:e2e:macos": "scripts/macos_e2e.sh 'build'",
@@ -73,6 +74,7 @@
7374
"@babel/preset-env": "^7.20.0",
7475
"@react-native/babel-preset": "^0.75.0",
7576
"@react-native/metro-config": "^0.75.0",
77+
"@rnx-kit/jest-preset": "^0.1.16",
7678
"@rnx-kit/metro-config": "^2.0.0",
7779
"@types/lodash": "^4.14.184",
7880
"@types/mocha": "^10.0.1",
@@ -122,6 +124,11 @@
122124
"jsSrcsDir": "./src",
123125
"android": {
124126
"javaPackageName": "com.reactnativecommunity.asyncstorage"
127+
},
128+
"windows": {
129+
"namespace": "RNCAsyncStorage",
130+
"outputDirectory": "windows/code/codegen",
131+
"separateDataTypes": true
125132
}
126133
}
127134
}

0 commit comments

Comments
 (0)