From 2e0bd0631f8af5444452a9153d716bf98d1ebb77 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 7 Jan 2025 09:08:43 -0800 Subject: [PATCH] Introduce getDiffProps for (#45552) Summary: In this diff I'm overriding the getDiffProps for ViewProps. The goal is to verify what's the impact of calculating diffs of props in Android, starting with ViewProps. Once we verify what are the implication we will automatic implement this diffing. The full implementation of this method will be implemented in the following diffs changelog: [internal] internal Reviewed By: NickGerleman Differential Revision: D59969328 --- .../components/view/HostPlatformViewProps.cpp | 21 +++++++++++++++++++ .../components/view/HostPlatformViewProps.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp index dfbae60abd7c94..352b8274c929db 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp @@ -133,4 +133,25 @@ SharedDebugStringConvertibleList HostPlatformViewProps::getDebugProps() const { } #endif +#ifdef ANDROID + +folly::dynamic HostPlatformViewProps::getDiffProps( + const Props* prevProps) const { + folly::dynamic result = folly::dynamic::object(); + + static const auto defaultProps = HostPlatformViewProps(); + + const HostPlatformViewProps* oldProps = prevProps == nullptr + ? &defaultProps + : static_cast(prevProps); + + if (focusable != oldProps->focusable) { + result["focusable"] = focusable; + } + + return result; +} + +#endif + } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h index 25a6cd30529b1a..d18d7e863bbdf9 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h @@ -55,6 +55,12 @@ class HostPlatformViewProps : public BaseViewProps { #if RN_DEBUG_STRING_CONVERTIBLE SharedDebugStringConvertibleList getDebugProps() const override; #endif + +#ifdef ANDROID + + folly::dynamic getDiffProps(const Props* prevProps) const override; + +#endif }; } // namespace facebook::react