Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support RN 74 on iOS #90

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@react-native/eslint-plugin-specs": "^0.72.4",
"@tsconfig/node10": "^1.0.9",
"@types/jest": "^28.1.4",
"@types/react": "^18.2.21",
"@types/react": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"babel-jest": "^29.6.4",
Expand Down
70 changes: 41 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,38 +115,50 @@ const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({

export function applyFSPropertiesWithRef(existingRef?: ForwardedRef<unknown>) {
return function (element: React.ElementRef<FSComponentType>) {
// https://github.com/facebook/react-native/blob/87d2ea9c364c7ea393d11718c195dfe580c916ef/packages/react-native/Libraries/Components/TextInput/TextInputState.js#L109C23-L109C67
// @ts-expect-error `currentProps` is missing in `NativeMethods`
const currentProps = element?.currentProps as Record<keyof NativeCommands, string | object>;
if (isTurboModuleEnabled && Platform.OS === 'ios' && currentProps) {
const fsClass = currentProps.fsClass as string;
if (fsClass) {
Commands.fsClass(element, fsClass);
}

const fsAttribute = currentProps.fsAttribute as object;
if (fsAttribute) {
Commands.fsAttribute(element, fsAttribute);
}

const fsTagName = currentProps.fsTagName as string;
if (fsTagName) {
Commands.fsTagName(element, fsTagName);
}
if (isTurboModuleEnabled && Platform.OS === 'ios') {
let currentProps: Record<keyof NativeCommands, string | object>;

const dataElement = currentProps.dataElement as string;
if (dataElement) {
Commands.dataElement(element, dataElement);
}
const getInternalInstanceHandleFromPublicInstance =
require('react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance').getInternalInstanceHandleFromPublicInstance;

const dataComponent = currentProps.dataComponent as string;
if (dataComponent) {
Commands.dataComponent(element, dataComponent);
if (getInternalInstanceHandleFromPublicInstance && element) {
currentProps =
getInternalInstanceHandleFromPublicInstance(element)?.stateNode?.canonical.currentProps;
} else {
// https://github.com/facebook/react-native/blob/87d2ea9c364c7ea393d11718c195dfe580c916ef/packages/react-native/Libraries/Components/TextInput/TextInputState.js#L109C23-L109C67
// @ts-expect-error `currentProps` is missing in `NativeMethods`
currentProps = element?.currentProps;
}

const dataSourceFile = currentProps.dataSourceFile as string;
if (dataSourceFile) {
Commands.dataSourceFile(element, dataSourceFile);
if (currentProps) {
const fsClass = currentProps.fsClass as string;
if (fsClass) {
Commands.fsClass(element, fsClass);
}

const fsAttribute = currentProps.fsAttribute as object;
if (fsAttribute) {
Commands.fsAttribute(element, fsAttribute);
}

const fsTagName = currentProps.fsTagName as string;
if (fsTagName) {
Commands.fsTagName(element, fsTagName);
}

const dataElement = currentProps.dataElement as string;
if (dataElement) {
Commands.dataElement(element, dataElement);
}

const dataComponent = currentProps.dataComponent as string;
if (dataComponent) {
Commands.dataComponent(element, dataComponent);
}

const dataSourceFile = currentProps.dataSourceFile as string;
if (dataSourceFile) {
Commands.dataSourceFile(element, dataSourceFile);
}
}
}

Expand Down