From f911ffd33dda767ab7261b20f3b023b7d8364d5c Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Fri, 17 Jun 2022 21:35:35 +0100 Subject: [PATCH 01/18] Prepared titlebar for native node size update Based this off of react native screens. Copied the RNSScreen hand written state/descriptor/shadownode at https://github.com/software-mansion/react-native-screens/tree/main/common/cpp/rnscreens. Need these to use c++ state. Updated podspec to include the cpp in the source files. Also set interfaceOnly in the native spec otherwise it generates some of these classes and so get a clash. Now hand writing descriptor, for example, so don't want react native codegen'ing it --- .gitignore | 1 + .../src/TitleBarNativeComponent.js | 1 + .../src/cpp/NVTitleBarComponentDescriptor.h | 41 +++++++++++++++++ .../src/cpp/NVTitleBarShadowNode.cpp | 9 ++++ .../src/cpp/NVTitleBarShadowNode.h | 29 ++++++++++++ .../src/cpp/NVTitleBarState.cpp | 14 ++++++ .../src/cpp/NVTitleBarState.h | 46 +++++++++++++++++++ .../src/ios/NVTitleBarComponentView.mm | 13 ++++++ .../navigation-react-native.podspec | 2 +- gulpfile.js | 2 + 10 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 NavigationReactNative/src/cpp/NVTitleBarComponentDescriptor.h create mode 100644 NavigationReactNative/src/cpp/NVTitleBarShadowNode.cpp create mode 100644 NavigationReactNative/src/cpp/NVTitleBarShadowNode.h create mode 100644 NavigationReactNative/src/cpp/NVTitleBarState.cpp create mode 100644 NavigationReactNative/src/cpp/NVTitleBarState.h diff --git a/.gitignore b/.gitignore index b44b123ab..3eb810b32 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ build/dist build/npm/**/navigation*.js build/npm/**/android build/npm/**/ios +build/npm/**/cpp build/npm/**/*NativeComponent.js npm-debug.log node_modules diff --git a/NavigationReactNative/src/TitleBarNativeComponent.js b/NavigationReactNative/src/TitleBarNativeComponent.js index 8fbbac970..a5560d964 100644 --- a/NavigationReactNative/src/TitleBarNativeComponent.js +++ b/NavigationReactNative/src/TitleBarNativeComponent.js @@ -14,4 +14,5 @@ type NativeProps = $ReadOnly<{| export default (codegenNativeComponent( 'NVTitleBar', + {interfaceOnly: true} ): HostComponent); diff --git a/NavigationReactNative/src/cpp/NVTitleBarComponentDescriptor.h b/NavigationReactNative/src/cpp/NVTitleBarComponentDescriptor.h new file mode 100644 index 000000000..0548b486a --- /dev/null +++ b/NavigationReactNative/src/cpp/NVTitleBarComponentDescriptor.h @@ -0,0 +1,41 @@ +#pragma once + +#include +#include "NVTitleBarShadowNode.h" +#include + +namespace facebook { +namespace react { + +class NVTitleBarComponentDescriptor final + : public ConcreteComponentDescriptor { + public: + using ConcreteComponentDescriptor::ConcreteComponentDescriptor; + + void adopt(ShadowNode::Unshared const &shadowNode) const override { + react_native_assert( + std::dynamic_pointer_cast(shadowNode)); + auto screenShadowNode = + std::static_pointer_cast(shadowNode); + + react_native_assert( + std::dynamic_pointer_cast(screenShadowNode)); + auto layoutableShadowNode = + std::static_pointer_cast(screenShadowNode); + + auto state = + std::static_pointer_cast( + shadowNode->getState()); + auto stateData = state->getData(); + + if (stateData.frameSize.width != 0 && stateData.frameSize.height != 0) { + layoutableShadowNode->setSize( + Size{stateData.frameSize.width, stateData.frameSize.height}); + } + + ConcreteComponentDescriptor::adopt(shadowNode); + } +}; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/NVTitleBarShadowNode.cpp b/NavigationReactNative/src/cpp/NVTitleBarShadowNode.cpp new file mode 100644 index 000000000..0660d3ad0 --- /dev/null +++ b/NavigationReactNative/src/cpp/NVTitleBarShadowNode.cpp @@ -0,0 +1,9 @@ +#include "NVTitleBarShadowNode.h" + +namespace facebook { +namespace react { + +extern const char NVTitleBarComponentName[] = "NVTitleBar"; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/NVTitleBarShadowNode.h b/NavigationReactNative/src/cpp/NVTitleBarShadowNode.h new file mode 100644 index 000000000..b54351d75 --- /dev/null +++ b/NavigationReactNative/src/cpp/NVTitleBarShadowNode.h @@ -0,0 +1,29 @@ +#pragma once + +#include "NVTitleBarState.h" +#include +#include +#include + +namespace facebook { +namespace react { + +extern const char NVTitleBarComponentName[]; + +class NVTitleBarShadowNode final : public ConcreteViewShadowNode< + NVTitleBarComponentName, + NVTitleBarProps, + NVTitleBarEventEmitter, + NVTitleBarState> { + public: + using ConcreteViewShadowNode::ConcreteViewShadowNode; + + static ShadowNodeTraits BaseTraits() { + auto traits = ConcreteViewShadowNode::BaseTraits(); + traits.set(ShadowNodeTraits::Trait::RootNodeKind); + return traits; + } +}; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/NVTitleBarState.cpp b/NavigationReactNative/src/cpp/NVTitleBarState.cpp new file mode 100644 index 000000000..eba5ae2cc --- /dev/null +++ b/NavigationReactNative/src/cpp/NVTitleBarState.cpp @@ -0,0 +1,14 @@ +#include "NVTitleBarState.h" + +namespace facebook { +namespace react { + +#ifdef ANDROID +folly::dynamic NVTitleBarState::getDynamic() const { + return folly::dynamic::object("frameWidth", frameSize.width)( + "frameHeight", frameSize.height); +} +#endif + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/NVTitleBarState.h b/NavigationReactNative/src/cpp/NVTitleBarState.h new file mode 100644 index 000000000..5a041b712 --- /dev/null +++ b/NavigationReactNative/src/cpp/NVTitleBarState.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + +class NVTitleBarState final { + public: + using Shared = std::shared_ptr; + + NVTitleBarState(){}; + NVTitleBarState(Size frameSize_) : frameSize(frameSize_){}; + +#ifdef ANDROID + NVTitleBarState( + NVTitleBarState const &previousState, + folly::dynamic data) + : frameSize(Size{ + (Float)data["frameWidth"].getDouble(), + (Float)data["frameHeight"].getDouble()}){}; +#endif + + const Size frameSize{}; + +#ifdef ANDROID + folly::dynamic getDynamic() const; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; + +#endif + +#pragma mark - Getters +}; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/ios/NVTitleBarComponentView.mm b/NavigationReactNative/src/ios/NVTitleBarComponentView.mm index bcf3b418f..8a9c978c9 100644 --- a/NavigationReactNative/src/ios/NVTitleBarComponentView.mm +++ b/NavigationReactNative/src/ios/NVTitleBarComponentView.mm @@ -5,8 +5,10 @@ #import #import #import +#import #import "RCTFabricComponentsPlugins.h" +#import #import using namespace facebook::react; @@ -17,6 +19,7 @@ @interface NVTitleBarComponentView () @implementation NVTitleBarComponentView { CGRect _lastViewFrame; + facebook::react::NVTitleBarShadowNode::ConcreteState::Shared _state; } - (instancetype)initWithFrame:(CGRect)frame @@ -42,6 +45,10 @@ - (void)willMoveToSuperview:(UIView *)newSuperview { - (void)layoutSubviews { [super layoutSubviews]; + if (_state != nullptr) { + auto newState = facebook::react::NVTitleBarState{RCTSizeFromCGSize(self.bounds.size)}; + _state->updateState(std::move(newState)); + } if (!CGRectEqualToRect(_lastViewFrame, self.frame)) { std::static_pointer_cast(_eventEmitter) ->onChangeBounds(NVTitleBarEventEmitter::OnChangeBounds{ @@ -61,6 +68,12 @@ - (void)prepareForRecycle #pragma mark - RCTComponentViewProtocol +- (void)updateState:(facebook::react::State::Shared const &)state + oldState:(facebook::react::State::Shared const &)oldState +{ + _state = std::static_pointer_cast(state); +} + + (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider(); diff --git a/build/npm/navigation-react-native/navigation-react-native.podspec b/build/npm/navigation-react-native/navigation-react-native.podspec index f988cba65..d69207aaf 100644 --- a/build/npm/navigation-react-native/navigation-react-native.podspec +++ b/build/npm/navigation-react-native/navigation-react-native.podspec @@ -12,7 +12,7 @@ Pod::Spec.new do |spec| spec.platform = :ios, "9.0" spec.author = "Graham Mendick" spec.source = { :git => "git://github.com/grahammendick/navigation.git", :tag => "v8.9.0-NavigationReactNative" } - spec.source_files = "ios/**/*.{h,m,mm}" + spec.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{h,cpp}" spec.dependency "React-Core" if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then spec.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" diff --git a/gulpfile.js b/gulpfile.js index 8911e2221..cabe5e574 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -63,6 +63,7 @@ var cleanNative = () => { return del([ './build/npm/navigation-react-native/android', './build/npm/navigation-react-native/ios', + './build/npm/navigation-react-native/cpp', './build/npm/navigation-react-native/**/*NativeComponent.js' ]); }; @@ -70,6 +71,7 @@ var packageNative = () => { return src([ './NavigationReactNative/src/android/**/*', './NavigationReactNative/src/ios/**/*', + './NavigationReactNative/src/cpp/**/*', './NavigationReactNative/src/**/*NativeComponent.js' ], {base: './NavigationReactNative/src'}) .pipe(dest('./build/npm/navigation-react-native')); From 32dbed9103d75b510120e3b89bf62518219b58d2 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Fri, 17 Jun 2022 21:44:39 +0100 Subject: [PATCH 02/18] Tested the node size update and it works!! So removing the change bounds workaround. Tested using issue https://github.com/grahammendick/navigation/issues/515 --- NavigationReactNative/src/ios/NVTitleBarComponentView.mm | 8 -------- 1 file changed, 8 deletions(-) diff --git a/NavigationReactNative/src/ios/NVTitleBarComponentView.mm b/NavigationReactNative/src/ios/NVTitleBarComponentView.mm index 8a9c978c9..ab4ccc749 100644 --- a/NavigationReactNative/src/ios/NVTitleBarComponentView.mm +++ b/NavigationReactNative/src/ios/NVTitleBarComponentView.mm @@ -49,14 +49,6 @@ - (void)layoutSubviews { auto newState = facebook::react::NVTitleBarState{RCTSizeFromCGSize(self.bounds.size)}; _state->updateState(std::move(newState)); } - if (!CGRectEqualToRect(_lastViewFrame, self.frame)) { - std::static_pointer_cast(_eventEmitter) - ->onChangeBounds(NVTitleBarEventEmitter::OnChangeBounds{ - .width = static_cast(self.frame.size.width), - .height = static_cast(self.frame.size.height), - }); - _lastViewFrame = self.frame; - } } - (void)prepareForRecycle From 40d8638c9d2a44d1b168d0abd7d82db2dc50b2b4 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sat, 18 Jun 2022 09:16:37 +0100 Subject: [PATCH 03/18] Removed redundant namespace and reset in recycle Saw that RCTModalHostViewComponentView.mm in React Native doesn't use the facebook::react:: namespace qualifier --- NavigationReactNative/src/ios/NVTitleBarComponentView.mm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/NavigationReactNative/src/ios/NVTitleBarComponentView.mm b/NavigationReactNative/src/ios/NVTitleBarComponentView.mm index ab4ccc749..6f15543ef 100644 --- a/NavigationReactNative/src/ios/NVTitleBarComponentView.mm +++ b/NavigationReactNative/src/ios/NVTitleBarComponentView.mm @@ -19,7 +19,7 @@ @interface NVTitleBarComponentView () @implementation NVTitleBarComponentView { CGRect _lastViewFrame; - facebook::react::NVTitleBarShadowNode::ConcreteState::Shared _state; + NVTitleBarShadowNode::ConcreteState::Shared _state; } - (instancetype)initWithFrame:(CGRect)frame @@ -46,7 +46,7 @@ - (void)willMoveToSuperview:(UIView *)newSuperview { - (void)layoutSubviews { [super layoutSubviews]; if (_state != nullptr) { - auto newState = facebook::react::NVTitleBarState{RCTSizeFromCGSize(self.bounds.size)}; + auto newState = NVTitleBarState{RCTSizeFromCGSize(self.bounds.size)}; _state->updateState(std::move(newState)); } } @@ -54,6 +54,7 @@ - (void)layoutSubviews { - (void)prepareForRecycle { [super prepareForRecycle]; + _state.reset(); _lastViewFrame = CGRectMake(0, 0, 0, 0); self.reactViewController.navigationItem.titleView = nil; } @@ -63,7 +64,7 @@ - (void)prepareForRecycle - (void)updateState:(facebook::react::State::Shared const &)state oldState:(facebook::react::State::Shared const &)oldState { - _state = std::static_pointer_cast(state); + _state = std::static_pointer_cast(state); } + (ComponentDescriptorProvider)componentDescriptorProvider From 73400f1035407f40d5a1633ecd6ce3d11a434a41 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sat, 18 Jun 2022 09:34:21 +0100 Subject: [PATCH 04/18] Updated search bar node size in native Used c++ state - copied approach just added to title bar --- .../src/SearchBarNativeComponent.js | 1 + .../src/cpp/NVSearchBarComponentDescriptor.h | 41 +++++++++++++++++ .../src/cpp/NVSearchBarShadowNode.cpp | 9 ++++ .../src/cpp/NVSearchBarShadowNode.h | 29 ++++++++++++ .../src/cpp/NVSearchBarState.cpp | 14 ++++++ .../src/cpp/NVSearchBarState.h | 46 +++++++++++++++++++ .../src/ios/NVSearchBarComponentView.mm | 18 +++++--- 7 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 NavigationReactNative/src/cpp/NVSearchBarComponentDescriptor.h create mode 100644 NavigationReactNative/src/cpp/NVSearchBarShadowNode.cpp create mode 100644 NavigationReactNative/src/cpp/NVSearchBarShadowNode.h create mode 100644 NavigationReactNative/src/cpp/NVSearchBarState.cpp create mode 100644 NavigationReactNative/src/cpp/NVSearchBarState.h diff --git a/NavigationReactNative/src/SearchBarNativeComponent.js b/NavigationReactNative/src/SearchBarNativeComponent.js index afcbe01ea..ccd704fd1 100644 --- a/NavigationReactNative/src/SearchBarNativeComponent.js +++ b/NavigationReactNative/src/SearchBarNativeComponent.js @@ -36,4 +36,5 @@ type NativeProps = $ReadOnly<{| export default (codegenNativeComponent( 'NVSearchBar', + {interfaceOnly: true} ): HostComponent); diff --git a/NavigationReactNative/src/cpp/NVSearchBarComponentDescriptor.h b/NavigationReactNative/src/cpp/NVSearchBarComponentDescriptor.h new file mode 100644 index 000000000..a6468d670 --- /dev/null +++ b/NavigationReactNative/src/cpp/NVSearchBarComponentDescriptor.h @@ -0,0 +1,41 @@ +#pragma once + +#include +#include "NVSearchBarShadowNode.h" +#include + +namespace facebook { +namespace react { + +class NVSearchBarComponentDescriptor final + : public ConcreteComponentDescriptor { + public: + using ConcreteComponentDescriptor::ConcreteComponentDescriptor; + + void adopt(ShadowNode::Unshared const &shadowNode) const override { + react_native_assert( + std::dynamic_pointer_cast(shadowNode)); + auto screenShadowNode = + std::static_pointer_cast(shadowNode); + + react_native_assert( + std::dynamic_pointer_cast(screenShadowNode)); + auto layoutableShadowNode = + std::static_pointer_cast(screenShadowNode); + + auto state = + std::static_pointer_cast( + shadowNode->getState()); + auto stateData = state->getData(); + + if (stateData.frameSize.width != 0 && stateData.frameSize.height != 0) { + layoutableShadowNode->setSize( + Size{stateData.frameSize.width, stateData.frameSize.height}); + } + + ConcreteComponentDescriptor::adopt(shadowNode); + } +}; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/NVSearchBarShadowNode.cpp b/NavigationReactNative/src/cpp/NVSearchBarShadowNode.cpp new file mode 100644 index 000000000..ef517018a --- /dev/null +++ b/NavigationReactNative/src/cpp/NVSearchBarShadowNode.cpp @@ -0,0 +1,9 @@ +#include "NVSearchBarShadowNode.h" + +namespace facebook { +namespace react { + +extern const char NVSearchBarComponentName[] = "NVSearchBar"; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/NVSearchBarShadowNode.h b/NavigationReactNative/src/cpp/NVSearchBarShadowNode.h new file mode 100644 index 000000000..e6bf5aac5 --- /dev/null +++ b/NavigationReactNative/src/cpp/NVSearchBarShadowNode.h @@ -0,0 +1,29 @@ +#pragma once + +#include "NVSearchBarState.h" +#include +#include +#include + +namespace facebook { +namespace react { + +extern const char NVSearchBarComponentName[]; + +class NVSearchBarShadowNode final : public ConcreteViewShadowNode< + NVSearchBarComponentName, + NVSearchBarProps, + NVSearchBarEventEmitter, + NVSearchBarState> { + public: + using ConcreteViewShadowNode::ConcreteViewShadowNode; + + static ShadowNodeTraits BaseTraits() { + auto traits = ConcreteViewShadowNode::BaseTraits(); + traits.set(ShadowNodeTraits::Trait::RootNodeKind); + return traits; + } +}; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/NVSearchBarState.cpp b/NavigationReactNative/src/cpp/NVSearchBarState.cpp new file mode 100644 index 000000000..bfbffe81b --- /dev/null +++ b/NavigationReactNative/src/cpp/NVSearchBarState.cpp @@ -0,0 +1,14 @@ +#include "NVSearchBarState.h" + +namespace facebook { +namespace react { + +#ifdef ANDROID +folly::dynamic NVSearchBarState::getDynamic() const { + return folly::dynamic::object("frameWidth", frameSize.width)( + "frameHeight", frameSize.height); +} +#endif + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/NVSearchBarState.h b/NavigationReactNative/src/cpp/NVSearchBarState.h new file mode 100644 index 000000000..5e3cc2423 --- /dev/null +++ b/NavigationReactNative/src/cpp/NVSearchBarState.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + +class NVSearchBarState final { + public: + using Shared = std::shared_ptr; + + NVSearchBarState(){}; + NVSearchBarState(Size frameSize_) : frameSize(frameSize_){}; + +#ifdef ANDROID + NVSearchBarState( + NVSearchBarState const &previousState, + folly::dynamic data) + : frameSize(Size{ + (Float)data["frameWidth"].getDouble(), + (Float)data["frameHeight"].getDouble()}){}; +#endif + + const Size frameSize{}; + +#ifdef ANDROID + folly::dynamic getDynamic() const; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; + +#endif + +#pragma mark - Getters +}; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/ios/NVSearchBarComponentView.mm b/NavigationReactNative/src/ios/NVSearchBarComponentView.mm index fb35c6100..ca29d3e9e 100644 --- a/NavigationReactNative/src/ios/NVSearchBarComponentView.mm +++ b/NavigationReactNative/src/ios/NVSearchBarComponentView.mm @@ -6,6 +6,7 @@ #import #import #import +#import #import "RCTFabricComponentsPlugins.h" #import @@ -23,6 +24,7 @@ @implementation NVSearchBarComponentView UIView *_reactSubview; NSInteger _nativeEventCount; NSInteger _nativeButtonEventCount; + NVSearchBarShadowNode::ConcreteState::Shared _state; } - (instancetype)initWithFrame:(CGRect)frame @@ -145,6 +147,7 @@ - (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NS - (void)prepareForRecycle { [super prepareForRecycle]; + _state.reset(); _nativeEventCount = 0; _nativeButtonEventCount = 0; _oldSearchController = _searchController; @@ -154,12 +157,9 @@ - (void)prepareForRecycle - (void)notifyForBoundsChange:(CGRect)newBounds { - if (_reactSubview) { - std::static_pointer_cast(_eventEmitter) - ->onChangeBounds(NVSearchBarEventEmitter::OnChangeBounds{ - .width = static_cast(newBounds.size.width), - .height = static_cast(newBounds.size.height), - }); + if (_state != nullptr) { + auto newState = NVSearchBarState{RCTSizeFromCGSize(self.bounds.size)}; + _state->updateState(std::move(newState)); } } @@ -184,6 +184,12 @@ - (void)unmountChildComponentView:(UIView *)childCompo self.searchController.searchResultsController.view = nil; } +- (void)updateState:(facebook::react::State::Shared const &)state + oldState:(facebook::react::State::Shared const &)oldState +{ + _state = std::static_pointer_cast(state); +} + + (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider(); From 7103a6a84442a6b0ac22bd331d166cc8a82c87e6 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sun, 19 Jun 2022 00:39:54 +0100 Subject: [PATCH 05/18] Updated title view node size on android This is more complicated than ios because can't work out how to get the hand-written files included with the generated ones. For now, manually copied them to the generated folder android/build/generated/source/codegen/jni/react/renderer/components/navigation-react-native - but they'll probably be overwritten so think might have to have a custom Android.mk? Also had to store the latest > 0 left position otherwise the title bar loses its left position when the screen is rotated. Must be a fabric bug that the left gets reset when updating node size?! --- .../navigation/reactnative/TitleBarView.java | 79 +++++++++++-------- .../reactnative/TitleBarViewManager.java | 9 +++ 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java index 431cc3028..d4b72e558 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java @@ -3,18 +3,25 @@ import android.content.Context; import android.view.ViewGroup; +import androidx.annotation.UiThread; + import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ReactContext; +import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; +import com.facebook.react.bridge.WritableNativeMap; +import com.facebook.react.uimanager.FabricViewStateManager; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.UIManagerHelper; import com.facebook.react.uimanager.events.Event; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.RCTEventEmitter; -public class TitleBarView extends ViewGroup { +public class TitleBarView extends ViewGroup implements FabricViewStateManager.HasFabricViewStateManager { private boolean layoutRequested = false; private int resizeLoopCount = 0; + private int left = 0; + private final FabricViewStateManager mFabricViewStateManager = new FabricViewStateManager(); public TitleBarView(Context context) { super(context); @@ -22,21 +29,46 @@ public TitleBarView(Context context) { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { + if (l > 0) left = l; } @Override protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); - if (Math.abs(w - oldw) > 5 || Math.abs(h - oldh) > 5) - resizeLoopCount = 0; - if (Math.abs(w - oldw) <= 5 && Math.abs(h - oldh) <= 5) - resizeLoopCount++; - if (resizeLoopCount <= 3) { - ReactContext reactContext = (ReactContext) getContext(); - EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, getId()); - eventDispatcher.dispatchEvent(new TitleBarView.ChangeBoundsEvent(getId(), w, h)); + updateState(w, h); + } + + @UiThread + public void updateState(final int width, final int height) { + final float realWidth = PixelUtil.toDIPFromPixel(width); + final float realHeight = PixelUtil.toDIPFromPixel(height); + + ReadableMap currentState = getFabricViewStateManager().getStateData(); + if (currentState != null) { + float delta = (float) 0.9; + float stateScreenHeight = + currentState.hasKey("frameHeight") + ? (float) currentState.getDouble("frameHeight") + : 0; + float stateScreenWidth = + currentState.hasKey("frameWidth") ? (float) currentState.getDouble("frameWidth") : 0; + + if (Math.abs(stateScreenWidth - realWidth) < delta + && Math.abs(stateScreenHeight - realHeight) < delta) { + return; + } } - requestLayout(); + + mFabricViewStateManager.setState( + new FabricViewStateManager.StateUpdateCallback() { + @Override + public WritableMap getStateUpdate() { + WritableMap map = new WritableNativeMap(); + map.putDouble("frameWidth", realWidth); + map.putDouble("frameHeight", realHeight); + return map; + } + }); } @Override @@ -55,31 +87,12 @@ public void run() { measure( MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY)); - layout(getLeft(), getTop(), getRight(), getBottom()); + layout(left, getTop(), getRight(), getBottom()); } }; - static class ChangeBoundsEvent extends Event { - private final int width; - private final int height; - - public ChangeBoundsEvent(int viewId, int width, int height) { - super(viewId); - this.width = width; - this.height = height; - } - - @Override - public String getEventName() { - return "topOnChangeBounds"; - } - - @Override - public void dispatch(RCTEventEmitter rctEventEmitter) { - WritableMap event = Arguments.createMap(); - event.putInt("width", (int) PixelUtil.toDIPFromPixel(this.width)); - event.putInt("height", (int) PixelUtil.toDIPFromPixel(this.height)); - rctEventEmitter.receiveEvent(getViewTag(), getEventName(), event); - } + @Override + public FabricViewStateManager getFabricViewStateManager() { + return mFabricViewStateManager; } } diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarViewManager.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarViewManager.java index 5e7c6bc27..0661186e7 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarViewManager.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarViewManager.java @@ -3,6 +3,8 @@ import androidx.annotation.Nullable; import com.facebook.react.common.MapBuilder; +import com.facebook.react.uimanager.ReactStylesDiffMap; +import com.facebook.react.uimanager.StateWrapper; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.ViewManagerDelegate; @@ -44,4 +46,11 @@ public Map getExportedCustomDirectEventTypeConstants() { .put("topOnChangeBounds", MapBuilder.of("registrationName", "onChangeBounds")) .build(); } + + @Override + public Object updateState( + TitleBarView view, ReactStylesDiffMap props, StateWrapper stateWrapper) { + view.getFabricViewStateManager().setStateWrapper(stateWrapper); + return null; + } } From b69060044e02676111874931060a73c6a5a70c08 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sun, 19 Jun 2022 13:36:23 +0100 Subject: [PATCH 06/18] Moved into folder that matches the generated path Want the include for the custom ComponentDescriptors to match the generated include #include #include --- .../navigation-react-native}/NVSearchBarComponentDescriptor.h | 0 .../components/navigation-react-native}/NVSearchBarShadowNode.cpp | 0 .../components/navigation-react-native}/NVSearchBarShadowNode.h | 0 .../components/navigation-react-native}/NVSearchBarState.cpp | 0 .../components/navigation-react-native}/NVSearchBarState.h | 0 .../navigation-react-native}/NVTitleBarComponentDescriptor.h | 0 .../components/navigation-react-native}/NVTitleBarShadowNode.cpp | 0 .../components/navigation-react-native}/NVTitleBarShadowNode.h | 0 .../components/navigation-react-native}/NVTitleBarState.cpp | 0 .../components/navigation-react-native}/NVTitleBarState.h | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVSearchBarComponentDescriptor.h (100%) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVSearchBarShadowNode.cpp (100%) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVSearchBarShadowNode.h (100%) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVSearchBarState.cpp (100%) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVSearchBarState.h (100%) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVTitleBarComponentDescriptor.h (100%) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVTitleBarShadowNode.cpp (100%) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVTitleBarShadowNode.h (100%) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVTitleBarState.cpp (100%) rename NavigationReactNative/src/cpp/{ => react/renderer/components/navigation-react-native}/NVTitleBarState.h (100%) diff --git a/NavigationReactNative/src/cpp/NVSearchBarComponentDescriptor.h b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarComponentDescriptor.h similarity index 100% rename from NavigationReactNative/src/cpp/NVSearchBarComponentDescriptor.h rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarComponentDescriptor.h diff --git a/NavigationReactNative/src/cpp/NVSearchBarShadowNode.cpp b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarShadowNode.cpp similarity index 100% rename from NavigationReactNative/src/cpp/NVSearchBarShadowNode.cpp rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarShadowNode.cpp diff --git a/NavigationReactNative/src/cpp/NVSearchBarShadowNode.h b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarShadowNode.h similarity index 100% rename from NavigationReactNative/src/cpp/NVSearchBarShadowNode.h rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarShadowNode.h diff --git a/NavigationReactNative/src/cpp/NVSearchBarState.cpp b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarState.cpp similarity index 100% rename from NavigationReactNative/src/cpp/NVSearchBarState.cpp rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarState.cpp diff --git a/NavigationReactNative/src/cpp/NVSearchBarState.h b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarState.h similarity index 100% rename from NavigationReactNative/src/cpp/NVSearchBarState.h rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVSearchBarState.h diff --git a/NavigationReactNative/src/cpp/NVTitleBarComponentDescriptor.h b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarComponentDescriptor.h similarity index 100% rename from NavigationReactNative/src/cpp/NVTitleBarComponentDescriptor.h rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarComponentDescriptor.h diff --git a/NavigationReactNative/src/cpp/NVTitleBarShadowNode.cpp b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarShadowNode.cpp similarity index 100% rename from NavigationReactNative/src/cpp/NVTitleBarShadowNode.cpp rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarShadowNode.cpp diff --git a/NavigationReactNative/src/cpp/NVTitleBarShadowNode.h b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarShadowNode.h similarity index 100% rename from NavigationReactNative/src/cpp/NVTitleBarShadowNode.h rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarShadowNode.h diff --git a/NavigationReactNative/src/cpp/NVTitleBarState.cpp b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarState.cpp similarity index 100% rename from NavigationReactNative/src/cpp/NVTitleBarState.cpp rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarState.cpp diff --git a/NavigationReactNative/src/cpp/NVTitleBarState.h b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarState.h similarity index 100% rename from NavigationReactNative/src/cpp/NVTitleBarState.h rename to NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVTitleBarState.h From 25f70500728217d73a8aa64f9e97b89f5943312b Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sun, 19 Jun 2022 17:09:52 +0100 Subject: [PATCH 07/18] Renamed for consistency and removed unused imports --- .../com/navigation/reactnative/TitleBarView.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java index d4b72e558..9e60d06c7 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java @@ -5,23 +5,17 @@ import androidx.annotation.UiThread; -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.uimanager.FabricViewStateManager; import com.facebook.react.uimanager.PixelUtil; -import com.facebook.react.uimanager.UIManagerHelper; -import com.facebook.react.uimanager.events.Event; -import com.facebook.react.uimanager.events.EventDispatcher; -import com.facebook.react.uimanager.events.RCTEventEmitter; public class TitleBarView extends ViewGroup implements FabricViewStateManager.HasFabricViewStateManager { private boolean layoutRequested = false; private int resizeLoopCount = 0; private int left = 0; - private final FabricViewStateManager mFabricViewStateManager = new FabricViewStateManager(); + private final FabricViewStateManager fabricViewStateManager = new FabricViewStateManager(); public TitleBarView(Context context) { super(context); @@ -42,7 +36,6 @@ protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { public void updateState(final int width, final int height) { final float realWidth = PixelUtil.toDIPFromPixel(width); final float realHeight = PixelUtil.toDIPFromPixel(height); - ReadableMap currentState = getFabricViewStateManager().getStateData(); if (currentState != null) { float delta = (float) 0.9; @@ -58,8 +51,7 @@ public void updateState(final int width, final int height) { return; } } - - mFabricViewStateManager.setState( + fabricViewStateManager.setState( new FabricViewStateManager.StateUpdateCallback() { @Override public WritableMap getStateUpdate() { @@ -93,6 +85,6 @@ public void run() { @Override public FabricViewStateManager getFabricViewStateManager() { - return mFabricViewStateManager; + return fabricViewStateManager; } } From 6841ed787aa3ebbd4fcf084435afc0659ddfdb60 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sun, 19 Jun 2022 17:10:52 +0100 Subject: [PATCH 08/18] Removed redundant field --- .../src/main/java/com/navigation/reactnative/TitleBarView.java | 1 - 1 file changed, 1 deletion(-) diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java index 9e60d06c7..9c948ad9b 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java @@ -13,7 +13,6 @@ public class TitleBarView extends ViewGroup implements FabricViewStateManager.HasFabricViewStateManager { private boolean layoutRequested = false; - private int resizeLoopCount = 0; private int left = 0; private final FabricViewStateManager fabricViewStateManager = new FabricViewStateManager(); From c6f16f55ed91c5f005f0631281ae9686cfb6f3c1 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sun, 19 Jun 2022 21:36:27 +0100 Subject: [PATCH 09/18] Added c++/rendered state files for action bar --- .../src/ActionBarNativeComponent.js | 1 + .../NVActionBarComponentDescriptor.h | 41 +++++++++++++++++ .../NVActionBarShadowNode.cpp | 9 ++++ .../NVActionBarShadowNode.h | 29 ++++++++++++ .../NVActionBarState.cpp | 14 ++++++ .../NVActionBarState.h | 46 +++++++++++++++++++ 6 files changed, 140 insertions(+) create mode 100644 NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarComponentDescriptor.h create mode 100644 NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarShadowNode.cpp create mode 100644 NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarShadowNode.h create mode 100644 NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarState.cpp create mode 100644 NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarState.h diff --git a/NavigationReactNative/src/ActionBarNativeComponent.js b/NavigationReactNative/src/ActionBarNativeComponent.js index 3b4ee4551..d303fa0ea 100644 --- a/NavigationReactNative/src/ActionBarNativeComponent.js +++ b/NavigationReactNative/src/ActionBarNativeComponent.js @@ -16,4 +16,5 @@ type NativeProps = $ReadOnly<{| export default (codegenNativeComponent( 'NVActionBar', + {interfaceOnly: true} ): HostComponent); diff --git a/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarComponentDescriptor.h b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarComponentDescriptor.h new file mode 100644 index 000000000..f51dc5277 --- /dev/null +++ b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarComponentDescriptor.h @@ -0,0 +1,41 @@ +#pragma once + +#include +#include "NVActionBarShadowNode.h" +#include + +namespace facebook { +namespace react { + +class NVActionBarComponentDescriptor final + : public ConcreteComponentDescriptor { + public: + using ConcreteComponentDescriptor::ConcreteComponentDescriptor; + + void adopt(ShadowNode::Unshared const &shadowNode) const override { + react_native_assert( + std::dynamic_pointer_cast(shadowNode)); + auto screenShadowNode = + std::static_pointer_cast(shadowNode); + + react_native_assert( + std::dynamic_pointer_cast(screenShadowNode)); + auto layoutableShadowNode = + std::static_pointer_cast(screenShadowNode); + + auto state = + std::static_pointer_cast( + shadowNode->getState()); + auto stateData = state->getData(); + + if (stateData.frameSize.width != 0 && stateData.frameSize.height != 0) { + layoutableShadowNode->setSize( + Size{stateData.frameSize.width, stateData.frameSize.height}); + } + + ConcreteComponentDescriptor::adopt(shadowNode); + } +}; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarShadowNode.cpp b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarShadowNode.cpp new file mode 100644 index 000000000..3df04901b --- /dev/null +++ b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarShadowNode.cpp @@ -0,0 +1,9 @@ +#include "NVActionBarShadowNode.h" + +namespace facebook { +namespace react { + +extern const char NVActionBarComponentName[] = "NVActionBar"; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarShadowNode.h b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarShadowNode.h new file mode 100644 index 000000000..53e322a76 --- /dev/null +++ b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarShadowNode.h @@ -0,0 +1,29 @@ +#pragma once + +#include "NVActionBarState.h" +#include +#include +#include + +namespace facebook { +namespace react { + +extern const char NVActionBarComponentName[]; + +class NVActionBarShadowNode final : public ConcreteViewShadowNode< + NVActionBarComponentName, + NVActionBarProps, + NVActionBarEventEmitter, + NVActionBarState> { + public: + using ConcreteViewShadowNode::ConcreteViewShadowNode; + + static ShadowNodeTraits BaseTraits() { + auto traits = ConcreteViewShadowNode::BaseTraits(); + traits.set(ShadowNodeTraits::Trait::RootNodeKind); + return traits; + } +}; + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarState.cpp b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarState.cpp new file mode 100644 index 000000000..b2cda4d92 --- /dev/null +++ b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarState.cpp @@ -0,0 +1,14 @@ +#include "NVActionBarState.h" + +namespace facebook { +namespace react { + +#ifdef ANDROID +folly::dynamic NVActionBarState::getDynamic() const { + return folly::dynamic::object("frameWidth", frameSize.width)( + "frameHeight", frameSize.height); +} +#endif + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarState.h b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarState.h new file mode 100644 index 000000000..064b03e7a --- /dev/null +++ b/NavigationReactNative/src/cpp/react/renderer/components/navigation-react-native/NVActionBarState.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + +class NVActionBarState final { + public: + using Shared = std::shared_ptr; + + NVActionBarState(){}; + NVActionBarState(Size frameSize_) : frameSize(frameSize_){}; + +#ifdef ANDROID + NVActionBarState( + NVActionBarState const &previousState, + folly::dynamic data) + : frameSize(Size{ + (Float)data["frameWidth"].getDouble(), + (Float)data["frameHeight"].getDouble()}){}; +#endif + + const Size frameSize{}; + +#ifdef ANDROID + folly::dynamic getDynamic() const; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; + +#endif + +#pragma mark - Getters +}; + +} // namespace react +} // namespace facebook \ No newline at end of file From f5514a72d22043df579a0228e0422b9262986a01 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sun, 19 Jun 2022 21:45:31 +0100 Subject: [PATCH 10/18] Updated action bar node size in native Haven't tested but copied over from title bar - haven't copied over the left field, will test to see if it's needed --- .../navigation/reactnative/ActionBarView.java | 79 ++++++++++--------- .../reactnative/ActionBarViewManager.java | 9 +++ 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java index 33cddb779..75d4eb596 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java @@ -3,18 +3,22 @@ import android.content.Context; import android.view.ViewGroup; -import com.facebook.react.bridge.Arguments; +import androidx.annotation.UiThread; + import com.facebook.react.bridge.ReactContext; +import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; +import com.facebook.react.bridge.WritableNativeMap; +import com.facebook.react.uimanager.FabricViewStateManager; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.UIManagerHelper; import com.facebook.react.uimanager.events.Event; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.RCTEventEmitter; -public class ActionBarView extends ViewGroup { +public class ActionBarView extends ViewGroup implements FabricViewStateManager.HasFabricViewStateManager { private boolean layoutRequested = false; - private int resizeLoopCount = 0; + private final FabricViewStateManager fabricViewStateManager = new FabricViewStateManager(); public ActionBarView(Context context) { super(context); @@ -38,16 +42,38 @@ void collapsed() { void changeBounds(int width, int height, int oldw, int oldh) { super.onSizeChanged(width, height, oldw, oldh); - if (Math.abs(width - oldw) > 5 || Math.abs(height - oldh) > 5) - resizeLoopCount = 0; - if (Math.abs(width - oldw) <= 5 && Math.abs(height - oldh) <= 5) - resizeLoopCount++; - if (resizeLoopCount <= 3) { - ReactContext reactContext = (ReactContext) getContext(); - EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, getId()); - eventDispatcher.dispatchEvent(new ActionBarView.ChangeBoundsEvent(getId(), width, height)); + updateState(width, height); + } + + @UiThread + public void updateState(final int width, final int height) { + final float realWidth = PixelUtil.toDIPFromPixel(width); + final float realHeight = PixelUtil.toDIPFromPixel(height); + ReadableMap currentState = getFabricViewStateManager().getStateData(); + if (currentState != null) { + float delta = (float) 0.9; + float stateScreenHeight = + currentState.hasKey("frameHeight") + ? (float) currentState.getDouble("frameHeight") + : 0; + float stateScreenWidth = + currentState.hasKey("frameWidth") ? (float) currentState.getDouble("frameWidth") : 0; + + if (Math.abs(stateScreenWidth - realWidth) < delta + && Math.abs(stateScreenHeight - realHeight) < delta) { + return; + } } - requestLayout(); + fabricViewStateManager.setState( + new FabricViewStateManager.StateUpdateCallback() { + @Override + public WritableMap getStateUpdate() { + WritableMap map = new WritableNativeMap(); + map.putDouble("frameWidth", realWidth); + map.putDouble("frameHeight", realHeight); + return map; + } + }); } @Override @@ -70,6 +96,11 @@ public void run() { } }; + @Override + public FabricViewStateManager getFabricViewStateManager() { + return fabricViewStateManager; + } + static class ExpandedEvent extends Event { public ExpandedEvent(int viewId) { super(viewId); @@ -101,28 +132,4 @@ public void dispatch(RCTEventEmitter rctEventEmitter) { rctEventEmitter.receiveEvent(getViewTag(), getEventName(), null); } } - - static class ChangeBoundsEvent extends Event { - private final int width; - private final int height; - - public ChangeBoundsEvent(int viewId, int width, int height) { - super(viewId); - this.width = width; - this.height = height; - } - - @Override - public String getEventName() { - return "topOnChangeBounds"; - } - - @Override - public void dispatch(RCTEventEmitter rctEventEmitter) { - WritableMap event = Arguments.createMap(); - event.putInt("width", (int) PixelUtil.toDIPFromPixel(this.width)); - event.putInt("height", (int) PixelUtil.toDIPFromPixel(this.height)); - rctEventEmitter.receiveEvent(getViewTag(), getEventName(), event); - } - } } diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarViewManager.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarViewManager.java index 7e85c7c34..1df988813 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarViewManager.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarViewManager.java @@ -4,6 +4,8 @@ import androidx.annotation.Nullable; import com.facebook.react.common.MapBuilder; +import com.facebook.react.uimanager.ReactStylesDiffMap; +import com.facebook.react.uimanager.StateWrapper; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.ViewManagerDelegate; @@ -45,4 +47,11 @@ public Map getExportedCustomDirectEventTypeConstants() { .put("topOnChangeBounds", MapBuilder.of("registrationName", "onChangeBounds")) .build(); } + + @Override + public Object updateState( + ActionBarView view, ReactStylesDiffMap props, StateWrapper stateWrapper) { + view.getFabricViewStateManager().setStateWrapper(stateWrapper); + return null; + } } From 9b46209c9106b95cbbfb98b7d361ed69a8c4113f Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Fri, 24 Jun 2022 23:19:31 +0100 Subject: [PATCH 11/18] Reverted forcing left position of title bar It doesn't work reliably. The problem happens on orientation change with the title bar going back to left 0. Without this left change the problem always happens - prefer that for now. Should raise a react native bug because this is a change from old architecture. Might be because new arch doesn't call needsCustomLayoutForChildren?! --- .../main/java/com/navigation/reactnative/TitleBarView.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java index 9c948ad9b..e52f1783f 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java @@ -13,7 +13,6 @@ public class TitleBarView extends ViewGroup implements FabricViewStateManager.HasFabricViewStateManager { private boolean layoutRequested = false; - private int left = 0; private final FabricViewStateManager fabricViewStateManager = new FabricViewStateManager(); public TitleBarView(Context context) { @@ -22,7 +21,6 @@ public TitleBarView(Context context) { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { - if (l > 0) left = l; } @Override @@ -78,7 +76,7 @@ public void run() { measure( MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY)); - layout(left, getTop(), getRight(), getBottom()); + layout(getLeft(), getTop(), getRight(), getBottom()); } }; From 0dfc6f3d2be00069ab6d2da53729dbd5c57cf26a Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sat, 25 Jun 2022 13:52:55 +0100 Subject: [PATCH 12/18] Added back old arch way of update action bar size --- .../navigation/reactnative/ActionBarView.java | 19 ++++++++++++++++++- .../navigation/reactnative/BarButtonView.java | 2 -- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java index 75d4eb596..f98ef08b6 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java @@ -5,6 +5,7 @@ import androidx.annotation.UiThread; +import com.facebook.react.bridge.GuardedRunnable; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; @@ -12,6 +13,7 @@ import com.facebook.react.uimanager.FabricViewStateManager; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.UIManagerHelper; +import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.events.Event; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.RCTEventEmitter; @@ -42,7 +44,22 @@ void collapsed() { void changeBounds(int width, int height, int oldw, int oldh) { super.onSizeChanged(width, height, oldw, oldh); - updateState(width, height); + if (fabricViewStateManager.hasStateWrapper()) { + updateState(width, height); + } else { + final int viewTag = getId(); + final ReactContext reactContext = (ReactContext) getContext(); + reactContext.runOnNativeModulesQueueThread( + new GuardedRunnable(reactContext) { + @Override + public void runGuarded() { + UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class); + if (uiManager != null) + uiManager.updateNodeSize(viewTag, width, height); + } + }); + + } } @UiThread diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/BarButtonView.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/BarButtonView.java index b9f76c978..613a18b99 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/BarButtonView.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/BarButtonView.java @@ -14,11 +14,9 @@ import androidx.annotation.Nullable; import androidx.appcompat.view.CollapsibleActionView; -import com.facebook.react.bridge.GuardedRunnable; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.uimanager.UIManagerHelper; -import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.events.Event; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.RCTEventEmitter; From 7be7bdab26e72c4ccf273c7b58468bd26d610b92 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sat, 25 Jun 2022 14:05:17 +0100 Subject: [PATCH 13/18] Added back old arch way of updating title bar size --- .../navigation/reactnative/TitleBarView.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java index e52f1783f..9ee5e305c 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarView.java @@ -5,11 +5,14 @@ import androidx.annotation.UiThread; +import com.facebook.react.bridge.GuardedRunnable; +import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.uimanager.FabricViewStateManager; import com.facebook.react.uimanager.PixelUtil; +import com.facebook.react.uimanager.UIManagerModule; public class TitleBarView extends ViewGroup implements FabricViewStateManager.HasFabricViewStateManager { private boolean layoutRequested = false; @@ -26,7 +29,21 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { @Override protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); - updateState(w, h); + if (fabricViewStateManager.hasStateWrapper()) { + updateState(w, h); + } else { + final int viewTag = getId(); + final ReactContext reactContext = (ReactContext) getContext(); + reactContext.runOnNativeModulesQueueThread( + new GuardedRunnable(reactContext) { + @Override + public void runGuarded() { + UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class); + if (uiManager != null) + uiManager.updateNodeSize(viewTag, w, h); + } + }); + } } @UiThread From 35f997bb19000ea0e59bc4727ef24497102ba077 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sat, 25 Jun 2022 14:11:23 +0100 Subject: [PATCH 14/18] Made final so can access in guarded run --- .../src/main/java/com/navigation/reactnative/ActionBarView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java index f98ef08b6..0378133eb 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarView.java @@ -42,7 +42,7 @@ void collapsed() { eventDispatcher.dispatchEvent(new ActionBarView.CollapsedEvent(getId())); } - void changeBounds(int width, int height, int oldw, int oldh) { + void changeBounds(final int width, final int height, int oldw, int oldh) { super.onSizeChanged(width, height, oldw, oldh); if (fabricViewStateManager.hasStateWrapper()) { updateState(width, height); From 25ac7391365a5785ceca7430fa73f4e4f1061bf7 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sat, 25 Jun 2022 14:29:13 +0100 Subject: [PATCH 15/18] Updated navigation react native wip version Releasing a wip so can make a repo to demonstrate regression caused by Fabric not calling needsCustomLayoutForChildren --- .../navigation-react-native/navigation-react-native.podspec | 4 ++-- build/npm/navigation-react-native/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/npm/navigation-react-native/navigation-react-native.podspec b/build/npm/navigation-react-native/navigation-react-native.podspec index 293b9042b..167c2935b 100644 --- a/build/npm/navigation-react-native/navigation-react-native.podspec +++ b/build/npm/navigation-react-native/navigation-react-native.podspec @@ -5,13 +5,13 @@ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 Pod::Spec.new do |spec| spec.name = "navigation-react-native" - spec.version = "8.9.1" + spec.version = "8.9.1-wip.0" spec.license = "Apache-2.0" spec.summary = "React Native plugin for the Navigation router" spec.homepage = "http://grahammendick.github.io/navigation/" spec.platform = :ios, "9.0" spec.author = "Graham Mendick" - spec.source = { :git => "git://github.com/grahammendick/navigation.git", :tag => "v8.9.1-NavigationReactNative" } + spec.source = { :git => "git://github.com/grahammendick/navigation.git", :tag => "v8.9.1-wip.0-NavigationReactNative" } spec.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{h,cpp}" spec.dependency "React-Core" if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then diff --git a/build/npm/navigation-react-native/package.json b/build/npm/navigation-react-native/package.json index 6397e111b..e2506ed74 100644 --- a/build/npm/navigation-react-native/package.json +++ b/build/npm/navigation-react-native/package.json @@ -1,6 +1,6 @@ { "name": "navigation-react-native", - "version": "8.9.1", + "version": "8.9.1-wip.0", "description": "React Native plugin for the Navigation router", "main": "navigation.react.native.js", "types": "navigation.react.native.d.ts", From 8b3a1682acfbba2bab031aacaecab78bd2baa3c3 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sun, 26 Jun 2022 09:28:53 +0100 Subject: [PATCH 16/18] Deleted redundant change bounds event Action bar and Title bar update node size on native --- NavigationReactNative/src/ActionBar.tsx | 14 ++++++-------- .../src/ActionBarNativeComponent.js | 4 ---- NavigationReactNative/src/TitleBar.tsx | 18 +++++++----------- .../src/TitleBarNativeComponent.js | 4 ---- .../reactnative/ActionBarManager.java | 1 - .../reactnative/ActionBarViewManager.java | 1 - .../reactnative/TitleBarManager.java | 7 ------- .../reactnative/TitleBarViewManager.java | 7 ------- 8 files changed, 13 insertions(+), 43 deletions(-) diff --git a/NavigationReactNative/src/ActionBar.tsx b/NavigationReactNative/src/ActionBar.tsx index 43c0c01a6..e0f1430f5 100644 --- a/NavigationReactNative/src/ActionBar.tsx +++ b/NavigationReactNative/src/ActionBar.tsx @@ -1,15 +1,13 @@ -import React, {useState} from 'react' +import React from 'react' import { requireNativeComponent, Platform, StyleSheet } from 'react-native'; -const ActionBar = props => { - const [bounds, setBounds] = useState({}); - return Platform.OS == 'android' ? ( +const ActionBar = props => ( + Platform.OS == 'android' ? ( {setBounds({width, height})}} - style={[styles.actionView, bounds]} /> - ) : null; -}; + style={styles.actionView} /> + ) : null +); const NVActionBar = global.nativeFabricUIManager ? require('./ActionBarNativeComponent').default : requireNativeComponent('NVActionBar'); diff --git a/NavigationReactNative/src/ActionBarNativeComponent.js b/NavigationReactNative/src/ActionBarNativeComponent.js index d303fa0ea..b31be83bb 100644 --- a/NavigationReactNative/src/ActionBarNativeComponent.js +++ b/NavigationReactNative/src/ActionBarNativeComponent.js @@ -6,10 +6,6 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNati type NativeProps = $ReadOnly<{| ...ViewProps, - onChangeBounds: DirectEventHandler<$ReadOnly<{| - width: Float, - height: Float, - |}>>, onExpanded: DirectEventHandler, onCollapsed: DirectEventHandler, |}>; diff --git a/NavigationReactNative/src/TitleBar.tsx b/NavigationReactNative/src/TitleBar.tsx index 39195e654..04a663d2e 100644 --- a/NavigationReactNative/src/TitleBar.tsx +++ b/NavigationReactNative/src/TitleBar.tsx @@ -1,16 +1,12 @@ -import React, {useState} from 'react' +import React from 'react' import { requireNativeComponent, StyleSheet, Platform } from 'react-native'; -const TitleBar = ({style, ...props}) => { - const [bounds, setBounds] = useState({}); - return ( - {setBounds({width, height})}} - style={[Platform.OS === 'ios' && styles.titleBar, style, bounds]} - /> - ) -}; +const TitleBar = ({style, ...props}) => ( + +); const NVTitleBar = global.nativeFabricUIManager ? require('./TitleBarNativeComponent').default : requireNativeComponent('NVTitleBar'); diff --git a/NavigationReactNative/src/TitleBarNativeComponent.js b/NavigationReactNative/src/TitleBarNativeComponent.js index a5560d964..d80970b52 100644 --- a/NavigationReactNative/src/TitleBarNativeComponent.js +++ b/NavigationReactNative/src/TitleBarNativeComponent.js @@ -6,10 +6,6 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNati type NativeProps = $ReadOnly<{| ...ViewProps, - onChangeBounds: DirectEventHandler<$ReadOnly<{| - width: Float, - height: Float, - |}>>, |}>; export default (codegenNativeComponent( diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarManager.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarManager.java index 4c287769d..f2bee8011 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarManager.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarManager.java @@ -26,7 +26,6 @@ public Map getExportedCustomDirectEventTypeConstants() { return MapBuilder.builder() .put("topOnExpanded", MapBuilder.of("registrationName", "onExpanded")) .put("topOnCollapsed", MapBuilder.of("registrationName", "onCollapsed")) - .put("topOnChangeBounds", MapBuilder.of("registrationName", "onChangeBounds")) .build(); } } diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarViewManager.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarViewManager.java index 1df988813..24c9de58c 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarViewManager.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/ActionBarViewManager.java @@ -44,7 +44,6 @@ public Map getExportedCustomDirectEventTypeConstants() { return MapBuilder.builder() .put("topOnExpanded", MapBuilder.of("registrationName", "onExpanded")) .put("topOnCollapsed", MapBuilder.of("registrationName", "onCollapsed")) - .put("topOnChangeBounds", MapBuilder.of("registrationName", "onChangeBounds")) .build(); } diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarManager.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarManager.java index 97350735e..b1ad06c05 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarManager.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarManager.java @@ -20,11 +20,4 @@ public String getName() { protected TitleBarView createViewInstance(@Nonnull ThemedReactContext reactContext) { return new TitleBarView(reactContext); } - - @Override - public Map getExportedCustomDirectEventTypeConstants() { - return MapBuilder.builder() - .put("topOnChangeBounds", MapBuilder.of("registrationName", "onChangeBounds")) - .build(); - } } diff --git a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarViewManager.java b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarViewManager.java index 0661186e7..c3ecff0b0 100644 --- a/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarViewManager.java +++ b/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/TitleBarViewManager.java @@ -40,13 +40,6 @@ protected TitleBarView createViewInstance(@Nonnull ThemedReactContext reactConte return new TitleBarView(reactContext); } - @Override - public Map getExportedCustomDirectEventTypeConstants() { - return MapBuilder.builder() - .put("topOnChangeBounds", MapBuilder.of("registrationName", "onChangeBounds")) - .build(); - } - @Override public Object updateState( TitleBarView view, ReactStylesDiffMap props, StateWrapper stateWrapper) { From 17a2bd5055dbc164c04e5f76d665aa0d30b8ffe3 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sun, 26 Jun 2022 10:22:14 +0100 Subject: [PATCH 17/18] Imported action bar component descriptor Needed now it's interfaceOnly where the component descriptor is hand-written (not codegen'ed) --- NavigationReactNative/src/ios/NVActionBarComponentView.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/NavigationReactNative/src/ios/NVActionBarComponentView.mm b/NavigationReactNative/src/ios/NVActionBarComponentView.mm index 3fbdf8754..ca823faca 100644 --- a/NavigationReactNative/src/ios/NVActionBarComponentView.mm +++ b/NavigationReactNative/src/ios/NVActionBarComponentView.mm @@ -5,6 +5,7 @@ #import #import #import +#import #import "RCTFabricComponentsPlugins.h" From e9663a7b7f5f2dd34d4fd524f7dce31a6a266a42 Mon Sep 17 00:00:00 2001 From: Graham Mendick Date: Sun, 26 Jun 2022 10:26:37 +0100 Subject: [PATCH 18/18] Deleted redundant change bounds event Search bar and Title bar update node size on native --- NavigationReactNative/src/SearchBar.tsx | 10 ++-------- NavigationReactNative/src/SearchBarNativeComponent.js | 4 ---- NavigationReactNative/src/ios/NVSearchBarManager.m | 1 - NavigationReactNative/src/ios/NVSearchBarView.h | 1 - NavigationReactNative/src/ios/NVTitleBarManager.m | 2 -- NavigationReactNative/src/ios/NVTitleBarView.h | 2 -- 6 files changed, 2 insertions(+), 18 deletions(-) diff --git a/NavigationReactNative/src/SearchBar.tsx b/NavigationReactNative/src/SearchBar.tsx index c5137480f..95405b4a0 100644 --- a/NavigationReactNative/src/SearchBar.tsx +++ b/NavigationReactNative/src/SearchBar.tsx @@ -9,7 +9,6 @@ class SearchBar extends React.Component { this.ref = React.createRef(); this.onChangeText = this.onChangeText.bind(this); this.onChangeScopeButton = this.onChangeScopeButton.bind(this); - this.onChangeBounds = this.onChangeBounds.bind(this); } static defaultProps = { obscureBackground: true, @@ -32,12 +31,8 @@ class SearchBar extends React.Component { if (onChangeScopeButton) onChangeScopeButton(scopeButtons[scopeButton]) } - onChangeBounds({nativeEvent}) { - var {width, height} = nativeEvent; - this.setState({width, height}); - } render() { - var {show, width, height, mostRecentEventCount, mostRecentButtonEventCount} = this.state; + var {show, mostRecentEventCount, mostRecentButtonEventCount} = this.state; var {autoCapitalize, children, bottomBar, scopeButton, scopeButtons, ...props} = this.props; var constants = (UIManager as any).getViewManagerConfig('NVSearchBar').Constants; autoCapitalize = Platform.OS === 'android' ? constants.AutoCapitalize[autoCapitalize] : autoCapitalize; @@ -54,10 +49,9 @@ class SearchBar extends React.Component { mostRecentButtonEventCount={mostRecentButtonEventCount} onChangeText={this.onChangeText} onChangeScopeButton={this.onChangeScopeButton} - onChangeBounds={this.onChangeBounds} onExpand={() => this.setState({show: true})} onCollapse={() => this.setState({show: false})} - style={[styles.searchBar, showStyle, {width, height}]}> + style={[styles.searchBar, showStyle]}> {Platform.OS === 'ios' || this.state.show ? children : null} ); diff --git a/NavigationReactNative/src/SearchBarNativeComponent.js b/NavigationReactNative/src/SearchBarNativeComponent.js index ccd704fd1..76a608dbb 100644 --- a/NavigationReactNative/src/SearchBarNativeComponent.js +++ b/NavigationReactNative/src/SearchBarNativeComponent.js @@ -26,10 +26,6 @@ type NativeProps = $ReadOnly<{| scopeButton: Int32, eventCount: Int32, |}>>, - onChangeBounds: DirectEventHandler<$ReadOnly<{| - width: Float, - height: Float, - |}>>, onExpand: DirectEventHandler, onCollapse: DirectEventHandler, |}>; diff --git a/NavigationReactNative/src/ios/NVSearchBarManager.m b/NavigationReactNative/src/ios/NVSearchBarManager.m index bf9ba1014..f498282a5 100644 --- a/NavigationReactNative/src/ios/NVSearchBarManager.m +++ b/NavigationReactNative/src/ios/NVSearchBarManager.m @@ -28,6 +28,5 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(mostRecentButtonEventCount, NSInteger) RCT_EXPORT_VIEW_PROPERTY(onChangeText, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onChangeScopeButton, RCTDirectEventBlock) -RCT_EXPORT_VIEW_PROPERTY(onChangeBounds, RCTDirectEventBlock) @end diff --git a/NavigationReactNative/src/ios/NVSearchBarView.h b/NavigationReactNative/src/ios/NVSearchBarView.h index 3aa66f7fb..9de2c07f9 100644 --- a/NavigationReactNative/src/ios/NVSearchBarView.h +++ b/NavigationReactNative/src/ios/NVSearchBarView.h @@ -11,7 +11,6 @@ @property (nonatomic, assign) NSInteger mostRecentButtonEventCount; @property (nonatomic, copy) RCTBubblingEventBlock onChangeText; @property (nonatomic, copy) RCTDirectEventBlock onChangeScopeButton; -@property (nonatomic, copy) RCTDirectEventBlock onChangeBounds; -(id)initWithBridge: (RCTBridge *)bridge; diff --git a/NavigationReactNative/src/ios/NVTitleBarManager.m b/NavigationReactNative/src/ios/NVTitleBarManager.m index f96828443..833864754 100644 --- a/NavigationReactNative/src/ios/NVTitleBarManager.m +++ b/NavigationReactNative/src/ios/NVTitleBarManager.m @@ -13,6 +13,4 @@ - (UIView *)view { return [[NVTitleBarView alloc] initWithBridge:self.bridge]; } -RCT_EXPORT_VIEW_PROPERTY(onChangeBounds, RCTDirectEventBlock) - @end diff --git a/NavigationReactNative/src/ios/NVTitleBarView.h b/NavigationReactNative/src/ios/NVTitleBarView.h index 9fc40839d..a3135496b 100644 --- a/NavigationReactNative/src/ios/NVTitleBarView.h +++ b/NavigationReactNative/src/ios/NVTitleBarView.h @@ -4,8 +4,6 @@ @interface NVTitleBarView : UIView -@property (nonatomic, copy) RCTDirectEventBlock onChangeBounds; - -(id)initWithBridge: (RCTBridge *)bridge; @end