Skip to content

Commit 53ce247

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Add codegen for MixedType diffing (#52266)
Summary: Pull Request resolved: #52266 Native components may use `MixedType` properties in rare cases to hold untyped data. This diff adds support for serializing and prop diffing these types of props so that all of the props and object fields would be included in prop diffing results. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D77307169 fbshipit-source-id: ae6b00207ef857c9cfa4bdf9c235972915410a29
1 parent e441954 commit 53ce247

5 files changed

Lines changed: 14 additions & 3 deletions

File tree

packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,9 @@ folly::dynamic MixedPropNativeComponentViewProps::getDiffProps(
737737
}
738738
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
739739
740+
if (mixedProp != oldProps->mixedProp) {
741+
result[\\"mixedProp\\"] = mixedProp;
742+
}
740743
return result;
741744
}
742745
#endif

packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,9 @@ folly::dynamic MixedPropNativeComponentViewProps::getDiffProps(
737737
}
738738
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
739739
740+
if (mixedProp != oldProps->mixedProp) {
741+
result[\\"mixedProp\\"] = mixedProp;
742+
}
740743
return result;
741744
}
742745
#endif

packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ function generatePropsDiffString(
152152
result["${prop.name}"] = toDynamic(${prop.name});
153153
}`;
154154
case 'MixedTypeAnnotation':
155+
return `
156+
if (${prop.name} != oldProps->${prop.name}) {
157+
result["${prop.name}"] = ${prop.name};
158+
}`;
155159
default:
156160
// TODO: Implement diffProps for complex types
157161
return '';

packages/react-native-codegen/src/generators/components/GeneratePropsH.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,8 @@ function generateStruct(
755755
case 'Int32TypeAnnotation':
756756
case 'DoubleTypeAnnotation':
757757
case 'FloatTypeAnnotation':
758-
return `result["${name}"] = ${name};`;
759758
case 'MixedTypeAnnotation':
760-
// MixedTypeAnnotation does not support prop diffing codegen
761-
return '';
759+
return `result["${name}"] = ${name};`;
762760
default:
763761
return `result["${name}"] = ::facebook::react::toDynamic(${name});`;
764762
}

packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,9 @@ folly::dynamic MixedPropNativeComponentProps::getDiffProps(
11521152
}
11531153
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
11541154
1155+
if (mixedProp != oldProps->mixedProp) {
1156+
result[\\"mixedProp\\"] = mixedProp;
1157+
}
11551158
return result;
11561159
}
11571160
#endif

0 commit comments

Comments
 (0)