@onekeyfe/react-native-chart-webview 3.0.96 → 3.0.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/lib/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.cpp +97 -67
  2. package/lib/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.hpp +6 -1
  3. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/views/HybridChartWebviewManager.kt +26 -10
  4. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/views/HybridChartWebviewStateUpdater.kt +2 -2
  5. package/lib/nitrogen/generated/ios/c++/views/HybridChartWebviewComponent.mm +116 -82
  6. package/lib/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.cpp +18 -175
  7. package/lib/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.hpp +59 -61
  8. package/lib/nitrogen/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.cpp +97 -67
  9. package/lib/nitrogen/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.hpp +6 -1
  10. package/lib/nitrogen/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/views/HybridChartWebviewManager.kt +26 -10
  11. package/lib/nitrogen/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/views/HybridChartWebviewStateUpdater.kt +2 -2
  12. package/lib/nitrogen/nitrogen/generated/ios/c++/views/HybridChartWebviewComponent.mm +116 -82
  13. package/lib/nitrogen/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.cpp +18 -175
  14. package/lib/nitrogen/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.hpp +59 -61
  15. package/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.cpp +97 -67
  16. package/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.hpp +6 -1
  17. package/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/views/HybridChartWebviewManager.kt +26 -10
  18. package/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/views/HybridChartWebviewStateUpdater.kt +2 -2
  19. package/nitrogen/generated/ios/c++/views/HybridChartWebviewComponent.mm +116 -82
  20. package/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.cpp +18 -175
  21. package/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.hpp +59 -61
  22. package/package.json +4 -4
@@ -7,165 +7,33 @@
7
7
 
8
8
  #include "HybridChartWebviewComponent.hpp"
9
9
 
10
- #include <string>
11
- #include <exception>
12
- #include <utility>
13
- #include <NitroModules/NitroDefines.hpp>
14
- #include <NitroModules/JSIConverter.hpp>
15
- #include <NitroModules/PropNameIDCache.hpp>
16
- #include <react/renderer/core/RawValue.h>
17
- #include <react/renderer/core/ShadowNode.h>
18
- #include <react/renderer/core/ComponentDescriptor.h>
19
- #include <react/renderer/components/view/ViewProps.h>
10
+ #include <NitroModules/NitroHash.hpp>
11
+ #include <NitroModules/ReactProp.hpp>
20
12
 
21
13
  namespace margelo::nitro::chartwebview::views {
22
14
 
15
+ using namespace facebook;
16
+
23
17
  extern const char HybridChartWebviewComponentName[] = "ChartWebview";
24
18
 
25
19
  HybridChartWebviewProps::HybridChartWebviewProps(const react::PropsParserContext& context,
26
20
  const HybridChartWebviewProps& sourceProps,
27
21
  const react::RawProps& rawProps):
28
22
  react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
29
- uri([&]() -> CachedProp<std::optional<std::string>> {
30
- try {
31
- const react::RawValue* rawValue = rawProps.at("uri", nullptr, nullptr);
32
- if (rawValue == nullptr) return sourceProps.uri;
33
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
34
- return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.uri);
35
- } catch (const std::exception& exc) {
36
- throw std::runtime_error(std::string("ChartWebview.uri: ") + exc.what());
37
- }
38
- }()),
39
- localBundle([&]() -> CachedProp<std::optional<std::string>> {
40
- try {
41
- const react::RawValue* rawValue = rawProps.at("localBundle", nullptr, nullptr);
42
- if (rawValue == nullptr) return sourceProps.localBundle;
43
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
44
- return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.localBundle);
45
- } catch (const std::exception& exc) {
46
- throw std::runtime_error(std::string("ChartWebview.localBundle: ") + exc.what());
47
- }
48
- }()),
49
- entry([&]() -> CachedProp<std::optional<std::string>> {
50
- try {
51
- const react::RawValue* rawValue = rawProps.at("entry", nullptr, nullptr);
52
- if (rawValue == nullptr) return sourceProps.entry;
53
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
54
- return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.entry);
55
- } catch (const std::exception& exc) {
56
- throw std::runtime_error(std::string("ChartWebview.entry: ") + exc.what());
57
- }
58
- }()),
59
- paramsJson([&]() -> CachedProp<std::optional<std::string>> {
60
- try {
61
- const react::RawValue* rawValue = rawProps.at("paramsJson", nullptr, nullptr);
62
- if (rawValue == nullptr) return sourceProps.paramsJson;
63
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
64
- return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.paramsJson);
65
- } catch (const std::exception& exc) {
66
- throw std::runtime_error(std::string("ChartWebview.paramsJson: ") + exc.what());
67
- }
68
- }()),
69
- assetHost([&]() -> CachedProp<std::optional<std::string>> {
70
- try {
71
- const react::RawValue* rawValue = rawProps.at("assetHost", nullptr, nullptr);
72
- if (rawValue == nullptr) return sourceProps.assetHost;
73
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
74
- return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.assetHost);
75
- } catch (const std::exception& exc) {
76
- throw std::runtime_error(std::string("ChartWebview.assetHost: ") + exc.what());
77
- }
78
- }()),
79
- bridgeScript([&]() -> CachedProp<std::optional<std::string>> {
80
- try {
81
- const react::RawValue* rawValue = rawProps.at("bridgeScript", nullptr, nullptr);
82
- if (rawValue == nullptr) return sourceProps.bridgeScript;
83
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
84
- return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.bridgeScript);
85
- } catch (const std::exception& exc) {
86
- throw std::runtime_error(std::string("ChartWebview.bridgeScript: ") + exc.what());
87
- }
88
- }()),
89
- reuseKey([&]() -> CachedProp<std::optional<std::string>> {
90
- try {
91
- const react::RawValue* rawValue = rawProps.at("reuseKey", nullptr, nullptr);
92
- if (rawValue == nullptr) return sourceProps.reuseKey;
93
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
94
- return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.reuseKey);
95
- } catch (const std::exception& exc) {
96
- throw std::runtime_error(std::string("ChartWebview.reuseKey: ") + exc.what());
97
- }
98
- }()),
99
- pooled([&]() -> CachedProp<std::optional<bool>> {
100
- try {
101
- const react::RawValue* rawValue = rawProps.at("pooled", nullptr, nullptr);
102
- if (rawValue == nullptr) return sourceProps.pooled;
103
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
104
- return CachedProp<std::optional<bool>>::fromRawValue(*runtime, value, sourceProps.pooled);
105
- } catch (const std::exception& exc) {
106
- throw std::runtime_error(std::string("ChartWebview.pooled: ") + exc.what());
107
- }
108
- }()),
109
- active([&]() -> CachedProp<std::optional<bool>> {
110
- try {
111
- const react::RawValue* rawValue = rawProps.at("active", nullptr, nullptr);
112
- if (rawValue == nullptr) return sourceProps.active;
113
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
114
- return CachedProp<std::optional<bool>>::fromRawValue(*runtime, value, sourceProps.active);
115
- } catch (const std::exception& exc) {
116
- throw std::runtime_error(std::string("ChartWebview.active: ") + exc.what());
117
- }
118
- }()),
119
- webviewDebuggingEnabled([&]() -> CachedProp<std::optional<bool>> {
120
- try {
121
- const react::RawValue* rawValue = rawProps.at("webviewDebuggingEnabled", nullptr, nullptr);
122
- if (rawValue == nullptr) return sourceProps.webviewDebuggingEnabled;
123
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
124
- return CachedProp<std::optional<bool>>::fromRawValue(*runtime, value, sourceProps.webviewDebuggingEnabled);
125
- } catch (const std::exception& exc) {
126
- throw std::runtime_error(std::string("ChartWebview.webviewDebuggingEnabled: ") + exc.what());
127
- }
128
- }()),
129
- onMessage([&]() -> CachedProp<std::optional<std::function<void(const std::string& /* message */)>>> {
130
- try {
131
- const react::RawValue* rawValue = rawProps.at("onMessage", nullptr, nullptr);
132
- if (rawValue == nullptr) return sourceProps.onMessage;
133
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
134
- return CachedProp<std::optional<std::function<void(const std::string& /* message */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.onMessage);
135
- } catch (const std::exception& exc) {
136
- throw std::runtime_error(std::string("ChartWebview.onMessage: ") + exc.what());
137
- }
138
- }()),
139
- onLoadEnd([&]() -> CachedProp<std::optional<std::function<void()>>> {
140
- try {
141
- const react::RawValue* rawValue = rawProps.at("onLoadEnd", nullptr, nullptr);
142
- if (rawValue == nullptr) return sourceProps.onLoadEnd;
143
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
144
- return CachedProp<std::optional<std::function<void()>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.onLoadEnd);
145
- } catch (const std::exception& exc) {
146
- throw std::runtime_error(std::string("ChartWebview.onLoadEnd: ") + exc.what());
147
- }
148
- }()),
149
- onError([&]() -> CachedProp<std::optional<std::function<void(const std::string& /* message */)>>> {
150
- try {
151
- const react::RawValue* rawValue = rawProps.at("onError", nullptr, nullptr);
152
- if (rawValue == nullptr) return sourceProps.onError;
153
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
154
- return CachedProp<std::optional<std::function<void(const std::string& /* message */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.onError);
155
- } catch (const std::exception& exc) {
156
- throw std::runtime_error(std::string("ChartWebview.onError: ") + exc.what());
157
- }
158
- }()),
159
- hybridRef([&]() -> CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridChartWebviewSpec>& /* ref */)>>> {
160
- try {
161
- const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr);
162
- if (rawValue == nullptr) return sourceProps.hybridRef;
163
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
164
- return CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridChartWebviewSpec>& /* ref */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.hybridRef);
165
- } catch (const std::exception& exc) {
166
- throw std::runtime_error(std::string("ChartWebview.hybridRef: ") + exc.what());
167
- }
168
- }()) { }
23
+ uri(nitro::ReactProp<std::optional<std::string>>::fromRawValue("ChartWebview", "uri", rawProps, sourceProps.uri)),
24
+ localBundle(nitro::ReactProp<std::optional<std::string>>::fromRawValue("ChartWebview", "localBundle", rawProps, sourceProps.localBundle)),
25
+ entry(nitro::ReactProp<std::optional<std::string>>::fromRawValue("ChartWebview", "entry", rawProps, sourceProps.entry)),
26
+ paramsJson(nitro::ReactProp<std::optional<std::string>>::fromRawValue("ChartWebview", "paramsJson", rawProps, sourceProps.paramsJson)),
27
+ assetHost(nitro::ReactProp<std::optional<std::string>>::fromRawValue("ChartWebview", "assetHost", rawProps, sourceProps.assetHost)),
28
+ bridgeScript(nitro::ReactProp<std::optional<std::string>>::fromRawValue("ChartWebview", "bridgeScript", rawProps, sourceProps.bridgeScript)),
29
+ reuseKey(nitro::ReactProp<std::optional<std::string>>::fromRawValue("ChartWebview", "reuseKey", rawProps, sourceProps.reuseKey)),
30
+ pooled(nitro::ReactProp<std::optional<bool>>::fromRawValue("ChartWebview", "pooled", rawProps, sourceProps.pooled)),
31
+ active(nitro::ReactProp<std::optional<bool>>::fromRawValue("ChartWebview", "active", rawProps, sourceProps.active)),
32
+ webviewDebuggingEnabled(nitro::ReactProp<std::optional<bool>>::fromRawValue("ChartWebview", "webviewDebuggingEnabled", rawProps, sourceProps.webviewDebuggingEnabled)),
33
+ onMessage(nitro::ReactProp<std::optional<std::function<void(const std::string& /* message */)>>>::fromRawValue("ChartWebview", "onMessage", rawProps, sourceProps.onMessage)),
34
+ onLoadEnd(nitro::ReactProp<std::optional<std::function<void()>>>::fromRawValue("ChartWebview", "onLoadEnd", rawProps, sourceProps.onLoadEnd)),
35
+ onError(nitro::ReactProp<std::optional<std::function<void(const std::string& /* message */)>>>::fromRawValue("ChartWebview", "onError", rawProps, sourceProps.onError)),
36
+ hybridRef(nitro::ReactProp<std::optional<std::function<void(const std::shared_ptr<HybridChartWebviewSpec>& /* ref */)>>>::fromRawValue("ChartWebview", "hybridRef", rawProps, sourceProps.hybridRef)) { }
169
37
 
170
38
  bool HybridChartWebviewProps::filterObjectKeys(const std::string& propName) {
171
39
  switch (hashString(propName)) {
@@ -187,29 +55,4 @@ namespace margelo::nitro::chartwebview::views {
187
55
  }
188
56
  }
189
57
 
190
- HybridChartWebviewComponentDescriptor::HybridChartWebviewComponentDescriptor(const react::ComponentDescriptorParameters& parameters)
191
- : ConcreteComponentDescriptor(parameters,
192
- react::RawPropsParser()) {}
193
-
194
- std::shared_ptr<const react::Props> HybridChartWebviewComponentDescriptor::cloneProps(const react::PropsParserContext& context,
195
- const std::shared_ptr<const react::Props>& props,
196
- react::RawProps rawProps) const {
197
- // 1. Prepare raw props parser
198
- rawProps.parse(rawPropsParser_);
199
- // 2. Copy props with Nitro's cached copy constructor
200
- return HybridChartWebviewShadowNode::Props(context, /* & */ rawProps, props);
201
- }
202
-
203
- #ifdef ANDROID
204
- void HybridChartWebviewComponentDescriptor::adopt(react::ShadowNode& shadowNode) const {
205
- // This is called immediately after `ShadowNode` is created, cloned or in progress.
206
- // On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++.
207
- auto& concreteShadowNode = static_cast<HybridChartWebviewShadowNode&>(shadowNode);
208
- const std::shared_ptr<const HybridChartWebviewProps>& constProps = concreteShadowNode.getConcreteSharedProps();
209
- const std::shared_ptr<HybridChartWebviewProps>& props = std::const_pointer_cast<HybridChartWebviewProps>(constProps);
210
- HybridChartWebviewState state{props};
211
- concreteShadowNode.setStateData(std::move(state));
212
- }
213
- #endif
214
-
215
58
  } // namespace margelo::nitro::chartwebview::views
@@ -7,14 +7,15 @@
7
7
 
8
8
  #pragma once
9
9
 
10
- #include <optional>
11
- #include <NitroModules/NitroDefines.hpp>
12
- #include <NitroModules/NitroHash.hpp>
13
- #include <NitroModules/CachedProp.hpp>
14
- #include <react/renderer/core/ConcreteComponentDescriptor.h>
15
- #include <react/renderer/core/PropsParserContext.h>
10
+ #include <NitroModules/ReactProp.hpp>
11
+ #include <NitroModules/ViewComponentDescriptor.hpp>
12
+ #include <NitroModules/ViewPropsHolderState.hpp>
16
13
  #include <react/renderer/components/view/ConcreteViewShadowNode.h>
17
14
  #include <react/renderer/components/view/ViewProps.h>
15
+ #include <react/renderer/core/PropsParserContext.h>
16
+ #include <react/renderer/core/RawProps.h>
17
+
18
+ #include <string>
18
19
 
19
20
  #include <string>
20
21
  #include <optional>
@@ -42,20 +43,56 @@ namespace margelo::nitro::chartwebview::views {
42
43
  const react::RawProps& rawProps);
43
44
 
44
45
  public:
45
- CachedProp<std::optional<std::string>> uri;
46
- CachedProp<std::optional<std::string>> localBundle;
47
- CachedProp<std::optional<std::string>> entry;
48
- CachedProp<std::optional<std::string>> paramsJson;
49
- CachedProp<std::optional<std::string>> assetHost;
50
- CachedProp<std::optional<std::string>> bridgeScript;
51
- CachedProp<std::optional<std::string>> reuseKey;
52
- CachedProp<std::optional<bool>> pooled;
53
- CachedProp<std::optional<bool>> active;
54
- CachedProp<std::optional<bool>> webviewDebuggingEnabled;
55
- CachedProp<std::optional<std::function<void(const std::string& /* message */)>>> onMessage;
56
- CachedProp<std::optional<std::function<void()>>> onLoadEnd;
57
- CachedProp<std::optional<std::function<void(const std::string& /* message */)>>> onError;
58
- CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridChartWebviewSpec>& /* ref */)>>> hybridRef;
46
+ nitro::ReactProp<std::optional<std::string>> uri;
47
+ nitro::ReactProp<std::optional<std::string>> localBundle;
48
+ nitro::ReactProp<std::optional<std::string>> entry;
49
+ nitro::ReactProp<std::optional<std::string>> paramsJson;
50
+ nitro::ReactProp<std::optional<std::string>> assetHost;
51
+ nitro::ReactProp<std::optional<std::string>> bridgeScript;
52
+ nitro::ReactProp<std::optional<std::string>> reuseKey;
53
+ nitro::ReactProp<std::optional<bool>> pooled;
54
+ nitro::ReactProp<std::optional<bool>> active;
55
+ nitro::ReactProp<std::optional<bool>> webviewDebuggingEnabled;
56
+ nitro::ReactProp<std::optional<std::function<void(const std::string& /* message */)>>> onMessage;
57
+ nitro::ReactProp<std::optional<std::function<void()>>> onLoadEnd;
58
+ nitro::ReactProp<std::optional<std::function<void(const std::string& /* message */)>>> onError;
59
+ nitro::ReactProp<std::optional<std::function<void(const std::shared_ptr<HybridChartWebviewSpec>& /* ref */)>>> hybridRef;
60
+
61
+ [[nodiscard]]
62
+ bool hasSameProps(const HybridChartWebviewProps& other) const noexcept {
63
+ return uri.hasSameValue(other.uri) &&
64
+ localBundle.hasSameValue(other.localBundle) &&
65
+ entry.hasSameValue(other.entry) &&
66
+ paramsJson.hasSameValue(other.paramsJson) &&
67
+ assetHost.hasSameValue(other.assetHost) &&
68
+ bridgeScript.hasSameValue(other.bridgeScript) &&
69
+ reuseKey.hasSameValue(other.reuseKey) &&
70
+ pooled.hasSameValue(other.pooled) &&
71
+ active.hasSameValue(other.active) &&
72
+ webviewDebuggingEnabled.hasSameValue(other.webviewDebuggingEnabled) &&
73
+ onMessage.hasSameValue(other.onMessage) &&
74
+ onLoadEnd.hasSameValue(other.onLoadEnd) &&
75
+ onError.hasSameValue(other.onError) &&
76
+ hybridRef.hasSameValue(other.hybridRef);
77
+ }
78
+
79
+ [[nodiscard]]
80
+ bool hasAnyProvidedProps() const noexcept {
81
+ return uri.isProvided() ||
82
+ localBundle.isProvided() ||
83
+ entry.isProvided() ||
84
+ paramsJson.isProvided() ||
85
+ assetHost.isProvided() ||
86
+ bridgeScript.isProvided() ||
87
+ reuseKey.isProvided() ||
88
+ pooled.isProvided() ||
89
+ active.isProvided() ||
90
+ webviewDebuggingEnabled.isProvided() ||
91
+ onMessage.isProvided() ||
92
+ onLoadEnd.isProvided() ||
93
+ onError.isProvided() ||
94
+ hybridRef.isProvided();
95
+ }
59
96
 
60
97
  private:
61
98
  static bool filterObjectKeys(const std::string& propName);
@@ -64,32 +101,7 @@ namespace margelo::nitro::chartwebview::views {
64
101
  /**
65
102
  * State for the "ChartWebview" View.
66
103
  */
67
- class HybridChartWebviewState final {
68
- public:
69
- HybridChartWebviewState() = default;
70
- explicit HybridChartWebviewState(const std::shared_ptr<HybridChartWebviewProps>& props):
71
- _props(props) {}
72
-
73
- public:
74
- [[nodiscard]]
75
- const std::shared_ptr<HybridChartWebviewProps>& getProps() const {
76
- return _props;
77
- }
78
-
79
- public:
80
- #ifdef ANDROID
81
- HybridChartWebviewState(const HybridChartWebviewState& /* previousState */, folly::dynamic /* data */) {}
82
- folly::dynamic getDynamic() const {
83
- throw std::runtime_error("HybridChartWebviewState does not support folly!");
84
- }
85
- react::MapBuffer getMapBuffer() const {
86
- throw std::runtime_error("HybridChartWebviewState does not support MapBuffer!");
87
- };
88
- #endif
89
-
90
- private:
91
- std::shared_ptr<HybridChartWebviewProps> _props;
92
- };
104
+ using HybridChartWebviewState = nitro::ViewPropsHolderState<HybridChartWebviewProps>;
93
105
 
94
106
  /**
95
107
  * The Shadow Node for the "ChartWebview" View.
@@ -102,21 +114,7 @@ namespace margelo::nitro::chartwebview::views {
102
114
  /**
103
115
  * The Component Descriptor for the "ChartWebview" View.
104
116
  */
105
- class HybridChartWebviewComponentDescriptor final: public react::ConcreteComponentDescriptor<HybridChartWebviewShadowNode> {
106
- public:
107
- explicit HybridChartWebviewComponentDescriptor(const react::ComponentDescriptorParameters& parameters);
108
-
109
- public:
110
- /**
111
- * A faster path for cloning props - reuses the caching logic from `HybridChartWebviewProps`.
112
- */
113
- std::shared_ptr<const react::Props> cloneProps(const react::PropsParserContext& context,
114
- const std::shared_ptr<const react::Props>& props,
115
- react::RawProps rawProps) const override;
116
- #ifdef ANDROID
117
- void adopt(react::ShadowNode& shadowNode) const override;
118
- #endif
119
- };
117
+ using HybridChartWebviewComponentDescriptor = nitro::ViewComponentDescriptor<HybridChartWebviewShadowNode>;
120
118
 
121
119
  /* The actual view for "ChartWebview" needs to be implemented in platform-specific code. */
122
120
 
@@ -15,89 +15,119 @@ namespace margelo::nitro::chartwebview::views {
15
15
  using namespace facebook;
16
16
  using ConcreteStateData = react::ConcreteState<HybridChartWebviewState>;
17
17
 
18
- void JHybridChartWebviewStateUpdater::updateViewProps(jni::alias_ref<jni::JClass> /* class */,
19
- jni::alias_ref<JHybridChartWebviewSpec::JavaPart> javaView,
20
- jni::alias_ref<JStateWrapper::javaobject> stateWrapperInterface) {
21
- std::shared_ptr<JHybridChartWebviewSpec> hybridView = javaView->getJHybridChartWebviewSpec();
22
-
18
+ std::shared_ptr<const HybridChartWebviewProps> JHybridChartWebviewStateUpdater::getPropsFromStateWrapper(
19
+ jni::alias_ref<JStateWrapper::javaobject> stateWrapper) {
20
+ if (stateWrapper.get() == nullptr) {
21
+ return nullptr;
22
+ }
23
23
  // Get concrete StateWrapperImpl from passed StateWrapper interface object
24
- jobject rawStateWrapper = stateWrapperInterface.get();
25
- if (!stateWrapperInterface->isInstanceOf(react::StateWrapperImpl::javaClassStatic())) [[unlikely]] {
26
- throw std::runtime_error("StateWrapper is not a StateWrapperImpl");
24
+ jobject rawStateWrapper = stateWrapper.get();
25
+ if (!stateWrapper->isInstanceOf(react::StateWrapperImpl::javaClassStatic())) [[unlikely]] {
26
+ throw std::runtime_error("StateWrapper is not a StateWrapperImpl");
27
+ }
28
+ auto stateWrapperImpl = jni::alias_ref<react::StateWrapperImpl::javaobject>{
29
+ static_cast<react::StateWrapperImpl::javaobject>(rawStateWrapper)
30
+ };
31
+ std::shared_ptr<const react::State> state = stateWrapperImpl->cthis()->getState();
32
+ if (state == nullptr) {
33
+ return nullptr;
27
34
  }
28
- auto stateWrapper = jni::alias_ref<react::StateWrapperImpl::javaobject>{
29
- static_cast<react::StateWrapperImpl::javaobject>(rawStateWrapper)};
30
- std::shared_ptr<const react::State> state = stateWrapper->cthis()->getState();
31
35
  auto concreteState = std::static_pointer_cast<const ConcreteStateData>(state);
32
36
  const HybridChartWebviewState& data = concreteState->getData();
33
- const std::shared_ptr<HybridChartWebviewProps>& props = data.getProps();
37
+ const std::shared_ptr<const HybridChartWebviewProps>& props = data.getProps();
34
38
  if (props == nullptr) [[unlikely]] {
35
- // Props aren't set yet!
36
39
  throw std::runtime_error("HybridChartWebviewState's data doesn't contain any props!");
37
40
  }
41
+ return props;
42
+ }
38
43
 
39
- // Update all props if they are dirty
40
- if (props->uri.isDirty) {
41
- hybridView->setUri(props->uri.value);
42
- props->uri.isDirty = false;
43
- }
44
- if (props->localBundle.isDirty) {
45
- hybridView->setLocalBundle(props->localBundle.value);
46
- props->localBundle.isDirty = false;
47
- }
48
- if (props->entry.isDirty) {
49
- hybridView->setEntry(props->entry.value);
50
- props->entry.isDirty = false;
51
- }
52
- if (props->paramsJson.isDirty) {
53
- hybridView->setParamsJson(props->paramsJson.value);
54
- props->paramsJson.isDirty = false;
55
- }
56
- if (props->assetHost.isDirty) {
57
- hybridView->setAssetHost(props->assetHost.value);
58
- props->assetHost.isDirty = false;
59
- }
60
- if (props->bridgeScript.isDirty) {
61
- hybridView->setBridgeScript(props->bridgeScript.value);
62
- props->bridgeScript.isDirty = false;
63
- }
64
- if (props->reuseKey.isDirty) {
65
- hybridView->setReuseKey(props->reuseKey.value);
66
- props->reuseKey.isDirty = false;
67
- }
68
- if (props->pooled.isDirty) {
69
- hybridView->setPooled(props->pooled.value);
70
- props->pooled.isDirty = false;
71
- }
72
- if (props->active.isDirty) {
73
- hybridView->setActive(props->active.value);
74
- props->active.isDirty = false;
75
- }
76
- if (props->webviewDebuggingEnabled.isDirty) {
77
- hybridView->setWebviewDebuggingEnabled(props->webviewDebuggingEnabled.value);
78
- props->webviewDebuggingEnabled.isDirty = false;
79
- }
80
- if (props->onMessage.isDirty) {
81
- hybridView->setOnMessage(props->onMessage.value);
82
- props->onMessage.isDirty = false;
83
- }
84
- if (props->onLoadEnd.isDirty) {
85
- hybridView->setOnLoadEnd(props->onLoadEnd.value);
86
- props->onLoadEnd.isDirty = false;
44
+ void JHybridChartWebviewStateUpdater::updateViewProps(jni::alias_ref<jni::JClass> /* class */,
45
+ jni::alias_ref<JHybridChartWebviewSpec::JavaPart> javaView,
46
+ jni::alias_ref<JStateWrapper::javaobject> newState,
47
+ jni::alias_ref<JStateWrapper::javaobject> oldState) {
48
+ std::shared_ptr<JHybridChartWebviewSpec> hybridView = javaView->getJHybridChartWebviewSpec();
49
+ std::shared_ptr<const HybridChartWebviewProps> newProps = getPropsFromStateWrapper(newState);
50
+ std::shared_ptr<const HybridChartWebviewProps> oldProps = getPropsFromStateWrapper(oldState);
51
+ if (newProps == nullptr) [[unlikely]] {
52
+ throw std::runtime_error("Current StateWrapper doesn't contain any props!");
87
53
  }
88
- if (props->onError.isDirty) {
89
- hybridView->setOnError(props->onError.value);
90
- props->onError.isDirty = false;
54
+
55
+ // Update only props that differ from the previous State snapshot.
56
+ if (oldProps == nullptr
57
+ ? newProps->uri.isProvided()
58
+ : !newProps->uri.hasSameValue(oldProps->uri)) {
59
+ hybridView->setUri(newProps->uri.get());
60
+ }
61
+ if (oldProps == nullptr
62
+ ? newProps->localBundle.isProvided()
63
+ : !newProps->localBundle.hasSameValue(oldProps->localBundle)) {
64
+ hybridView->setLocalBundle(newProps->localBundle.get());
65
+ }
66
+ if (oldProps == nullptr
67
+ ? newProps->entry.isProvided()
68
+ : !newProps->entry.hasSameValue(oldProps->entry)) {
69
+ hybridView->setEntry(newProps->entry.get());
70
+ }
71
+ if (oldProps == nullptr
72
+ ? newProps->paramsJson.isProvided()
73
+ : !newProps->paramsJson.hasSameValue(oldProps->paramsJson)) {
74
+ hybridView->setParamsJson(newProps->paramsJson.get());
75
+ }
76
+ if (oldProps == nullptr
77
+ ? newProps->assetHost.isProvided()
78
+ : !newProps->assetHost.hasSameValue(oldProps->assetHost)) {
79
+ hybridView->setAssetHost(newProps->assetHost.get());
80
+ }
81
+ if (oldProps == nullptr
82
+ ? newProps->bridgeScript.isProvided()
83
+ : !newProps->bridgeScript.hasSameValue(oldProps->bridgeScript)) {
84
+ hybridView->setBridgeScript(newProps->bridgeScript.get());
85
+ }
86
+ if (oldProps == nullptr
87
+ ? newProps->reuseKey.isProvided()
88
+ : !newProps->reuseKey.hasSameValue(oldProps->reuseKey)) {
89
+ hybridView->setReuseKey(newProps->reuseKey.get());
90
+ }
91
+ if (oldProps == nullptr
92
+ ? newProps->pooled.isProvided()
93
+ : !newProps->pooled.hasSameValue(oldProps->pooled)) {
94
+ hybridView->setPooled(newProps->pooled.get());
95
+ }
96
+ if (oldProps == nullptr
97
+ ? newProps->active.isProvided()
98
+ : !newProps->active.hasSameValue(oldProps->active)) {
99
+ hybridView->setActive(newProps->active.get());
100
+ }
101
+ if (oldProps == nullptr
102
+ ? newProps->webviewDebuggingEnabled.isProvided()
103
+ : !newProps->webviewDebuggingEnabled.hasSameValue(oldProps->webviewDebuggingEnabled)) {
104
+ hybridView->setWebviewDebuggingEnabled(newProps->webviewDebuggingEnabled.get());
105
+ }
106
+ if (oldProps == nullptr
107
+ ? newProps->onMessage.isProvided()
108
+ : !newProps->onMessage.hasSameValue(oldProps->onMessage)) {
109
+ hybridView->setOnMessage(newProps->onMessage.get());
110
+ }
111
+ if (oldProps == nullptr
112
+ ? newProps->onLoadEnd.isProvided()
113
+ : !newProps->onLoadEnd.hasSameValue(oldProps->onLoadEnd)) {
114
+ hybridView->setOnLoadEnd(newProps->onLoadEnd.get());
115
+ }
116
+ if (oldProps == nullptr
117
+ ? newProps->onError.isProvided()
118
+ : !newProps->onError.hasSameValue(oldProps->onError)) {
119
+ hybridView->setOnError(newProps->onError.get());
91
120
  }
92
121
 
93
122
  // Update hybridRef if it changed
94
- if (props->hybridRef.isDirty) {
123
+ if (oldProps == nullptr
124
+ ? newProps->hybridRef.isProvided()
125
+ : !newProps->hybridRef.hasSameValue(oldProps->hybridRef)) {
95
126
  // hybridRef changed - call it with new this
96
- const auto& maybeFunc = props->hybridRef.value;
127
+ const auto& maybeFunc = newProps->hybridRef.get();
97
128
  if (maybeFunc.has_value()) {
98
129
  maybeFunc.value()(hybridView);
99
130
  }
100
- props->hybridRef.isDirty = false;
101
131
  }
102
132
  }
103
133
 
@@ -31,7 +31,12 @@ public:
31
31
  public:
32
32
  static void updateViewProps(jni::alias_ref<jni::JClass> /* class */,
33
33
  jni::alias_ref<JHybridChartWebviewSpec::JavaPart> view,
34
- jni::alias_ref<JStateWrapper::javaobject> stateWrapperInterface);
34
+ jni::alias_ref<JStateWrapper::javaobject> newState,
35
+ jni::alias_ref<JStateWrapper::javaobject> oldState);
36
+
37
+ private:
38
+ static std::shared_ptr<const HybridChartWebviewProps> getPropsFromStateWrapper(
39
+ jni::alias_ref<JStateWrapper::javaobject> stateWrapper);
35
40
 
36
41
  public:
37
42
  static void registerNatives() {
@@ -20,6 +20,14 @@ import com.margelo.nitro.chartwebview.*
20
20
  * Represents the React Native `ViewManager` for the "ChartWebview" Nitro HybridView.
21
21
  */
22
22
  public open class HybridChartWebviewManager: SimpleViewManager<View>() {
23
+ /**
24
+ * Represents the View and its last state snapshot (mutable)
25
+ */
26
+ private class HybridViewHolder(
27
+ val hybridView: HybridChartWebview,
28
+ var lastState: StateWrapper? = null,
29
+ )
30
+
23
31
  init {
24
32
  if (RecyclableView::class.java.isAssignableFrom(HybridChartWebview::class.java)) {
25
33
  // Enable view recycling
@@ -34,33 +42,41 @@ public open class HybridChartWebviewManager: SimpleViewManager<View>() {
34
42
  override fun createViewInstance(reactContext: ThemedReactContext): View {
35
43
  val hybridView = HybridChartWebview(reactContext)
36
44
  val view = hybridView.view
37
- view.setTag(associated_hybrid_view_tag, hybridView)
45
+ view.setTag(associated_hybrid_view_tag, HybridViewHolder(hybridView))
38
46
  return view
39
47
  }
40
48
 
41
49
  override fun updateState(view: View, props: ReactStylesDiffMap, stateWrapper: StateWrapper): Any? {
42
- val hybridView = getHybridView(view)
50
+ val holder = getHybridViewHolder(view)
43
51
  ?: throw Error("Couldn't find view $view in local views table!")
52
+ val hybridView = holder.hybridView
53
+ val oldState = holder.lastState
54
+ val newState = stateWrapper
44
55
 
45
56
  // 1. Update each prop individually
46
57
  hybridView.beforeUpdate()
47
- HybridChartWebviewStateUpdater.updateViewProps(hybridView, stateWrapper)
58
+ HybridChartWebviewStateUpdater.updateViewProps(hybridView, newState, oldState)
48
59
  hybridView.afterUpdate()
60
+ holder.lastState = newState
49
61
 
50
62
  // 2. Continue in base View props
51
- return super.updateState(view, props, stateWrapper)
63
+ return super.updateState(view, props, newState)
52
64
  }
53
65
 
54
66
  override fun onDropViewInstance(view: View) {
55
- val hybridView = getHybridView(view)
56
- hybridView?.onDropView()
67
+ val holder = getHybridViewHolder(view)
68
+ holder?.lastState = null
69
+ holder?.hybridView?.onDropView()
57
70
  return super.onDropViewInstance(view)
58
71
  }
59
72
 
60
73
  protected override fun prepareToRecycleView(reactContext: ThemedReactContext, view: View): View? {
61
- super.prepareToRecycleView(reactContext, view)
62
- val hybridView = getHybridView(view)
74
+ val preparedView = super.prepareToRecycleView(reactContext, view)
75
+ ?: return null
76
+ val holder = getHybridViewHolder(preparedView)
63
77
  ?: return null
78
+ val hybridView = holder.hybridView
79
+ holder.lastState = null
64
80
 
65
81
  @Suppress("USELESS_IS_CHECK")
66
82
  if (hybridView is RecyclableView) {
@@ -74,7 +90,7 @@ public open class HybridChartWebviewManager: SimpleViewManager<View>() {
74
90
  }
75
91
  }
76
92
 
77
- private fun getHybridView(view: View): HybridChartWebview? {
78
- return view.getTag(associated_hybrid_view_tag) as? HybridChartWebview
93
+ private fun getHybridViewHolder(view: View): HybridViewHolder? {
94
+ return view.getTag(associated_hybrid_view_tag) as? HybridViewHolder
79
95
  }
80
96
  }
@@ -14,10 +14,10 @@ internal class HybridChartWebviewStateUpdater {
14
14
  companion object {
15
15
  /**
16
16
  * Updates the props for [view] through C++.
17
- * The [state] prop is expected to contain [view]'s props as wrapped Fabric state.
17
+ * The [newState] prop is expected to contain [view]'s props as wrapped Fabric state.
18
18
  */
19
19
  @Suppress("KotlinJniMissingFunction")
20
20
  @JvmStatic
21
- external fun updateViewProps(view: HybridChartWebviewSpec, state: StateWrapper)
21
+ external fun updateViewProps(view: HybridChartWebviewSpec, newState: StateWrapper, oldState: StateWrapper?)
22
22
  }
23
23
  }