From 6d7e6755ed049ae5e1cfc12cfb5fc25708bd741f Mon Sep 17 00:00:00 2001 From: wwwcg Date: Tue, 10 Oct 2023 23:41:10 +0800 Subject: [PATCH] refactor(ios): Revert rename Hippy prefix to NativeRender part 11 --- docs/development/native-component.md | 6 +-- .../HippyDemo/HippyConvenientBridge.mm | 1 + .../HippyDemo/myview/MyViewManager.mm | 2 +- .../native/ios/renderer/HippyComponentData.mm | 4 +- renderer/native/ios/renderer/HippyUIManager.h | 28 ++++++++--- .../native/ios/renderer/HippyUIManager.mm | 21 ++++++++- .../native/ios/renderer/NativeRenderManager.h | 7 +++ .../ios/renderer/NativeRenderManager.mm | 5 ++ .../NativeRenderFooterRefreshManager.mm | 6 +-- .../NativeRenderHeaderRefreshManager.mm | 6 +-- .../image/NativeRenderImageViewManager.mm | 4 +- .../NativeRenderBaseListViewManager.mm | 4 +- .../NativeRenderNavigatorViewManager.mm | 4 +- .../NativeRenderRefreshWrapperViewManager.mm | 4 +- .../scrollview/HippyScrollViewManager.mm | 6 +-- .../NativeRenderSmartViewPagerViewManager.mm | 6 +-- .../component/text/NativeRenderTextManager.mm | 4 +- .../textinput/NativeRenderTextView.mm | 2 +- .../textinput/NativeRenderTextViewManager.mm | 14 +++--- .../component/view/HippyViewManager.h | 19 ++++++-- .../component/view/HippyViewManager.mm | 47 +++++++++---------- .../viewPager/NativeRenderViewPagerManager.mm | 2 +- .../NativeRenderWaterfallViewManager.mm | 14 +++--- 23 files changed, 135 insertions(+), 81 deletions(-) diff --git a/docs/development/native-component.md b/docs/development/native-component.md index b89f53a4d35..adb9e21db34 100644 --- a/docs/development/native-component.md +++ b/docs/development/native-component.md @@ -183,13 +183,13 @@ protected void onAttachedToWindow() { ## 创建对应的ViewManager > ViewManager 是对应的视图管理组件,负责前端视图和终端视图直接进行属性、方法的调用。 -> SDK 中最基础的 `ViewManager` 是 `NativeRenderViewManager`,封装了基本的方法,负责管理 `NativeRenderView`。 -> 用户自定的 `ViewManager` 必须继承自 `NativeRenderViewManager`。 +> SDK 中最基础的 `ViewManager` 是 `HippyViewManager`,封装了基本的方法,负责管理 `NativeRenderView`。 +> 用户自定的 `ViewManager` 必须继承自 `HippyViewManager`。 NativeRenderMyViewManager.h ```objectivec -@interface NativeRenderMyViewManager:NativeRenderViewManager +@interface NativeRenderMyViewManager:HippyViewManager @end ``` diff --git a/framework/examples/ios-demo/HippyDemo/HippyConvenientBridge.mm b/framework/examples/ios-demo/HippyDemo/HippyConvenientBridge.mm index f939f7e7e9f..a1f703f6dc6 100644 --- a/framework/examples/ios-demo/HippyDemo/HippyConvenientBridge.mm +++ b/framework/examples/ios-demo/HippyDemo/HippyConvenientBridge.mm @@ -88,6 +88,7 @@ - (void)setUpNativeRenderManager { _nativeRenderManager->AddImageProviderClass([HippyDefaultImageProvider class]); _nativeRenderManager->RegisterExtraComponent(_extraComponents); _nativeRenderManager->SetVFSUriLoader([self URILoader]); + _nativeRenderManager->SetHippyBridge(self.bridge); _bridge.renderManager = _nativeRenderManager; } diff --git a/framework/examples/ios-demo/HippyDemo/myview/MyViewManager.mm b/framework/examples/ios-demo/HippyDemo/myview/MyViewManager.mm index 19700a725cf..6e39b85f4e4 100644 --- a/framework/examples/ios-demo/HippyDemo/myview/MyViewManager.mm +++ b/framework/examples/ios-demo/HippyDemo/myview/MyViewManager.mm @@ -33,7 +33,7 @@ @implementation MyViewManager HIPPY_EXPORT_METHOD(changeColor:(nonnull NSNumber *)reactTag color:(NSString *)color) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[reactTag]; if (view == nil || ![view isKindOfClass:[MyView class]]) { HippyLogError(@"tried to setPage: on an error viewPager %@ " diff --git a/renderer/native/ios/renderer/HippyComponentData.mm b/renderer/native/ios/renderer/HippyComponentData.mm index 66d358dbbff..7efbeb6bb44 100644 --- a/renderer/native/ios/renderer/HippyComponentData.mm +++ b/renderer/native/ios/renderer/HippyComponentData.mm @@ -89,7 +89,7 @@ - (instancetype)initWithViewManager:(HippyViewManager *)viewManager viewName:(NS while (cls != [HippyViewManager class]) { _implementsUIBlockToAmendWithRenderObjectRegistry = _implementsUIBlockToAmendWithRenderObjectRegistry - || HippyClassOverridesInstanceMethod(cls, @selector(uiBlockToAmendWithRenderObjectRegistry:)); + || HippyClassOverridesInstanceMethod(cls, @selector(uiBlockToAmendWithShadowViewRegistry:)); cls = [cls superclass]; } } @@ -511,7 +511,7 @@ - (NSString *)selectorStringFromSignature:(NSString *)signature { - (HippyViewManagerUIBlock)uiBlockToAmendWithRenderObjectViewRegistry:(NSDictionary *)registry { if (_implementsUIBlockToAmendWithRenderObjectRegistry) { - return [[self manager] uiBlockToAmendWithRenderObjectRegistry:registry]; + return [[self manager] uiBlockToAmendWithShadowViewRegistry:registry]; } return nil; } diff --git a/renderer/native/ios/renderer/HippyUIManager.h b/renderer/native/ios/renderer/HippyUIManager.h index 6e4edb17cc2..bd2bb6ae1f2 100644 --- a/renderer/native/ios/renderer/HippyUIManager.h +++ b/renderer/native/ios/renderer/HippyUIManager.h @@ -21,7 +21,7 @@ */ #import - +#import "HippyBridge.h" #import "HippyInvalidating.h" #import "NativeRenderDefines.h" #import "HippyBridgeModule.h" @@ -64,10 +64,11 @@ class HippyValue; @property(nonatomic, assign) BOOL uiCreationLazilyEnabled; -@property(nonatomic, assign) std::weak_ptr VFSUriLoader; -@property(nonatomic, assign) std::weak_ptr renderManager; -@property(nonatomic, readonly) std::weak_ptr domManager; -@property(nonatomic, readonly) HippyComponentMap *viewRegistry; +@property (nonatomic, weak) HippyBridge *bridge; +@property (nonatomic, assign) std::weak_ptr VFSUriLoader; +@property (nonatomic, assign) std::weak_ptr renderManager; +@property (nonatomic, readonly) std::weak_ptr domManager; +@property (nonatomic, readonly) HippyComponentMap *viewRegistry; - (void)addImageProviderClass:(Class)cls; - (NSArray> *)imageProviderClasses; @@ -123,7 +124,7 @@ class HippyValue; * @param hippyTag hippy tag corresponding to UIView * @return view created by hippy tag */ -- (UIView *)createViewRecursivelyFromcomponentTag:(NSNumber *)componentTag +- (UIView *)createViewRecursivelyFromcomponentTag:(NSNumber *)hippyTag onRootTag:(NSNumber *)rootTag; /** @@ -201,7 +202,7 @@ class HippyValue; */ - (id)dispatchFunction:(const std::string &)functionName viewName:(const std::string &)viewName - viewTag:(int32_t)componentTag + viewTag:(int32_t)hippyTag onRootNode:(std::weak_ptr)rootNode params:(const footstone::value::HippyValue &)params callback:(hippy::CallFunctionCallback)cb; @@ -252,3 +253,16 @@ class HippyValue; #endif @end + + +/** + * This category makes the current HippyUIManager instance available via the + * HippyBridge, which is useful for HippyBridgeModules or HippyViewManagers that + * need to access the HippyUIManager. + */ +@interface HippyBridge (HippyUIManager) + +/// The current HippyUIManager instance +@property (nonatomic, readonly) HippyUIManager *uiManager; + +@end diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 8644a24bfc0..b3be1d4710b 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -43,6 +43,7 @@ #import "NSObject+Render.h" #import "HippyBridgeModule.h" #import "HippyModulesSetup.h" +#import "NativeRenderManager.h" #include "dom/root_node.h" #include "objc/runtime.h" @@ -609,6 +610,7 @@ - (void)updateView:(nonnull NSNumber *)componentTag } #pragma mark Render Context Implementation + - (__kindof HippyViewManager *)renderViewManagerForViewName:(NSString *)viewName { if (!_viewManagers) { _viewManagers = [NSMutableDictionary dictionaryWithCapacity:64]; @@ -636,8 +638,8 @@ - (__kindof HippyViewManager *)renderViewManagerForViewName:(NSString *)viewName id object = [_viewManagers objectForKey:viewName]; if (object_isClass(object)) { HippyViewManager *viewManager = [object new]; - viewManager.renderImpl = self; - NSAssert([viewManager isKindOfClass:[HippyViewManager class]], @"It must be a NativeRenderViewManager instance"); + viewManager.bridge = self.bridge; + NSAssert([viewManager isKindOfClass:[HippyViewManager class]], @"It must be a HippyViewManager instance"); [_viewManagers setObject:viewManager forKey:viewName]; object = viewManager; } @@ -1529,3 +1531,18 @@ - (void)domEventDidHandle:(const std::string &)eventName forNode:(int32_t)tag on @end + +@implementation HippyBridge (HippyUIManager) + +- (HippyUIManager *)uiManager { + auto renderManager = [self renderManager].lock(); + if (renderManager) { + auto nativeRenderManager = std::static_pointer_cast(renderManager); + return nativeRenderManager->GetHippyUIManager(); + } + return nil; +} + +@end + + diff --git a/renderer/native/ios/renderer/NativeRenderManager.h b/renderer/native/ios/renderer/NativeRenderManager.h index 0c63791d34e..7673fe4f3d6 100644 --- a/renderer/native/ios/renderer/NativeRenderManager.h +++ b/renderer/native/ios/renderer/NativeRenderManager.h @@ -204,6 +204,13 @@ class NativeRenderManager : public hippy::RenderManager ,public std::enable_shar *@param loader vfs url loader instance */ void SetVFSUriLoader(std::shared_ptr loader); + + /** + * Set HippyBridge pointer to renderManager + * + *@param bridge HippyBridge instance + */ + void SetHippyBridge(HippyBridge *bridge); /** * Set root view size changed event callback diff --git a/renderer/native/ios/renderer/NativeRenderManager.mm b/renderer/native/ios/renderer/NativeRenderManager.mm index e1f17d80e16..07259efdeb2 100644 --- a/renderer/native/ios/renderer/NativeRenderManager.mm +++ b/renderer/native/ios/renderer/NativeRenderManager.mm @@ -233,6 +233,11 @@ } } +void NativeRenderManager::SetHippyBridge(HippyBridge *bridge) { + HippyAssert(renderImpl_, @"renderImpl_ is null, did you forget to call Initialize()?"); + renderImpl_.bridge = bridge; +} + void NativeRenderManager::SetRootViewSizeChangedEvent(std::function cb) { [renderImpl_ setRootViewSizeChangedEvent:cb]; } diff --git a/renderer/native/ios/renderer/component/footerrefresh/NativeRenderFooterRefreshManager.mm b/renderer/native/ios/renderer/component/footerrefresh/NativeRenderFooterRefreshManager.mm index 73e8445c3b3..c4a6d79b374 100644 --- a/renderer/native/ios/renderer/component/footerrefresh/NativeRenderFooterRefreshManager.mm +++ b/renderer/native/ios/renderer/component/footerrefresh/NativeRenderFooterRefreshManager.mm @@ -33,21 +33,21 @@ @implementation NativeRenderFooterRefreshManager HIPPY_EXPORT_VIEW_PROPERTY(onFooterPulling, HippyDirectEventBlock) HIPPY_EXPORT_METHOD(collapsePullFooter:(nonnull NSNumber *)reactTag) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { HippyRefresh *refreshView = viewRegistry[reactTag]; [refreshView refreshFinish]; }]; } HIPPY_EXPORT_METHOD(collapsePullFooterWithOptions:(nonnull NSNumber *)reactTag options:(NSDictionary *)options) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { HippyRefresh *refreshView = viewRegistry[reactTag]; [refreshView refreshFinishWithOption:options]; }]; } HIPPY_EXPORT_METHOD(expandPullFooter:(nonnull NSNumber *)reactTag) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { HippyRefresh *refreshView = viewRegistry[reactTag]; [refreshView refresh]; }]; diff --git a/renderer/native/ios/renderer/component/headerrefresh/NativeRenderHeaderRefreshManager.mm b/renderer/native/ios/renderer/component/headerrefresh/NativeRenderHeaderRefreshManager.mm index d79c2057ca8..a468d9f43d5 100644 --- a/renderer/native/ios/renderer/component/headerrefresh/NativeRenderHeaderRefreshManager.mm +++ b/renderer/native/ios/renderer/component/headerrefresh/NativeRenderHeaderRefreshManager.mm @@ -32,21 +32,21 @@ @implementation NativeRenderHeaderRefreshManager HIPPY_EXPORT_VIEW_PROPERTY(onHeaderPulling, HippyDirectEventBlock) HIPPY_EXPORT_METHOD(expandPullHeader:(nonnull NSNumber *)reactTag) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { HippyRefresh *refreshView = viewRegistry[reactTag]; [refreshView refresh]; }]; } HIPPY_EXPORT_METHOD(collapsePullHeader:(nonnull NSNumber *)reactTag) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { HippyRefresh *refreshView = viewRegistry[reactTag]; [refreshView refreshFinish]; }]; } HIPPY_EXPORT_METHOD(collapsePullHeaderWithOptions:(nonnull NSNumber *)reactTag options:(NSDictionary *)options) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { HippyRefresh *refreshView = viewRegistry[reactTag]; [refreshView refreshFinishWithOption:options]; }]; diff --git a/renderer/native/ios/renderer/component/image/NativeRenderImageViewManager.mm b/renderer/native/ios/renderer/component/image/NativeRenderImageViewManager.mm index b55708488d3..739f7153dbf 100644 --- a/renderer/native/ios/renderer/component/image/NativeRenderImageViewManager.mm +++ b/renderer/native/ios/renderer/component/image/NativeRenderImageViewManager.mm @@ -69,12 +69,12 @@ - (void)loadImageSource:(NSString *)path forView:(NativeRenderImageView *)view { } NSString *standardizeAssetUrlString = path; __weak NativeRenderImageView *weakView = view; - auto loader = [[self renderImpl] VFSUriLoader].lock(); + auto loader = [self.bridge.uiManager VFSUriLoader].lock(); if (!loader) { return; } loader->RequestUntrustedContent(path, nil, nil, ^(NSData *data, NSURLResponse *response, NSError *error) { - HippyUIManager *renderImpl = self.renderImpl; + HippyUIManager *renderImpl = self.bridge.uiManager; id imageProvider = nil; if (renderImpl) { for (Class cls in [renderImpl imageProviderClasses]) { diff --git a/renderer/native/ios/renderer/component/listview/NativeRenderBaseListViewManager.mm b/renderer/native/ios/renderer/component/listview/NativeRenderBaseListViewManager.mm index 1db96422487..179f0cc7be9 100644 --- a/renderer/native/ios/renderer/component/listview/NativeRenderBaseListViewManager.mm +++ b/renderer/native/ios/renderer/component/listview/NativeRenderBaseListViewManager.mm @@ -59,7 +59,7 @@ - (HippyShadowView *)hippyShadowView { xIndex:(__unused NSNumber *)xIndex yIndex:(NSNumber *)yIndex animation:(nonnull NSNumber *)animation) { - [self.renderImpl addUIBlock: + [self.bridge.uiManager addUIBlock: ^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ NativeRenderBaseListView *view = (NativeRenderBaseListView *)viewRegistry[componentTag]; if (view == nil) return ; @@ -74,7 +74,7 @@ - (HippyShadowView *)hippyShadowView { x:(nonnull NSNumber *)x y:(nonnull NSNumber *)y animation:(nonnull NSNumber *)animation) { - [self.renderImpl addUIBlock: + [self.bridge.uiManager addUIBlock: ^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ NativeRenderBaseListView *view = (NativeRenderBaseListView *)viewRegistry[componentTag]; if (view == nil) return ; diff --git a/renderer/native/ios/renderer/component/navigator/NativeRenderNavigatorViewManager.mm b/renderer/native/ios/renderer/component/navigator/NativeRenderNavigatorViewManager.mm index 1897c86df51..d6ce1ab6999 100644 --- a/renderer/native/ios/renderer/component/navigator/NativeRenderNavigatorViewManager.mm +++ b/renderer/native/ios/renderer/component/navigator/NativeRenderNavigatorViewManager.mm @@ -38,14 +38,14 @@ - (UIView *)view { } HIPPY_EXPORT_METHOD(push:(NSNumber *__nonnull)componentTag parms:(NSDictionary *__nonnull)params) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderNavigatorHostView *navigatorHostView = viewRegistry[componentTag]; [navigatorHostView push:params]; }]; } HIPPY_EXPORT_METHOD(pop:(NSNumber *__nonnull)componentTag parms:(NSDictionary *__nonnull)params) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderNavigatorHostView *navigatorHostView = viewRegistry[componentTag]; [navigatorHostView pop:params]; }]; diff --git a/renderer/native/ios/renderer/component/refreshview/NativeRenderRefreshWrapperViewManager.mm b/renderer/native/ios/renderer/component/refreshview/NativeRenderRefreshWrapperViewManager.mm index 81b24245914..2312a4c95dd 100644 --- a/renderer/native/ios/renderer/component/refreshview/NativeRenderRefreshWrapperViewManager.mm +++ b/renderer/native/ios/renderer/component/refreshview/NativeRenderRefreshWrapperViewManager.mm @@ -36,14 +36,14 @@ - (UIView *)view { } HIPPY_EXPORT_METHOD(refreshComplected:(NSNumber *__nonnull)componentTag) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderRefreshWrapper *wrapperView = viewRegistry[componentTag]; [wrapperView refreshCompleted]; }]; } HIPPY_EXPORT_METHOD(startRefresh:(NSNumber *__nonnull)componentTag) { - [self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderRefreshWrapper *wrapperView = viewRegistry[componentTag]; [wrapperView startRefresh]; }]; diff --git a/renderer/native/ios/renderer/component/scrollview/HippyScrollViewManager.mm b/renderer/native/ios/renderer/component/scrollview/HippyScrollViewManager.mm index 25a75f92b8e..c19a4d98989 100644 --- a/renderer/native/ios/renderer/component/scrollview/HippyScrollViewManager.mm +++ b/renderer/native/ios/renderer/component/scrollview/HippyScrollViewManager.mm @@ -100,7 +100,7 @@ - (UIView *)view { HIPPY_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)componentTag callback:(HippyPromiseResolveBlock)callback) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { HippyScrollView *view = viewRegistry[componentTag]; CGSize size = view.scrollView.contentSize; callback(@{@"width" : @(size.width),@"height" : @(size.height)}); @@ -111,7 +111,7 @@ - (UIView *)view { offsetX:(NSNumber *)x offsetY:(NSNumber *)y animated:(NSNumber *)animated) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[componentTag]; if (view == nil) return ; if ([view conformsToProtocol:@protocol(HippyScrollableProtocol)]) { @@ -125,7 +125,7 @@ - (UIView *)view { HIPPY_EXPORT_METHOD(scrollToWithOptions:(nonnull NSNumber *)componentTag options:(NSDictionary *)options) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[componentTag]; if (view == nil) return ; if ([view conformsToProtocol:@protocol(HippyScrollableProtocol)]) { diff --git a/renderer/native/ios/renderer/component/smartViewPager/NativeRenderSmartViewPagerViewManager.mm b/renderer/native/ios/renderer/component/smartViewPager/NativeRenderSmartViewPagerViewManager.mm index 7e1d66cf3e3..facd86c4a93 100644 --- a/renderer/native/ios/renderer/component/smartViewPager/NativeRenderSmartViewPagerViewManager.mm +++ b/renderer/native/ios/renderer/component/smartViewPager/NativeRenderSmartViewPagerViewManager.mm @@ -50,7 +50,7 @@ - (UIView *)view { HIPPY_EXPORT_METHOD(setPage:(nonnull NSNumber *)componentTag pageNumber:(NSNumber *)pageNumber) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[componentTag]; if (view == nil || ![view isKindOfClass:[NativeRenderSmartViewPagerView class]]) { @@ -64,7 +64,7 @@ - (UIView *)view { HIPPY_EXPORT_METHOD(setPageWithoutAnimation:(nonnull NSNumber *)componentTag pageNumber:(NSNumber *)pageNumber) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[componentTag]; if (view == nil || ![view isKindOfClass:[NativeRenderSmartViewPagerView class]]) { HippyLogError(@"tried to setPage: on an error viewPager %@ " @@ -77,7 +77,7 @@ - (UIView *)view { HIPPY_EXPORT_METHOD(getPageIndex:(nonnull NSNumber *)componentTag callback:(HippyPromiseResolveBlock)callback) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderSmartViewPagerView *view = viewRegistry[componentTag]; NSInteger currrentPage = [view getCurrentPage]; callback(@(currrentPage)); diff --git a/renderer/native/ios/renderer/component/text/NativeRenderTextManager.mm b/renderer/native/ios/renderer/component/text/NativeRenderTextManager.mm index a4d83d897b1..369de267217 100644 --- a/renderer/native/ios/renderer/component/text/NativeRenderTextManager.mm +++ b/renderer/native/ios/renderer/component/text/NativeRenderTextManager.mm @@ -83,7 +83,7 @@ - (HippyShadowView *)hippyShadowView { HIPPY_EXPORT_SHADOW_PROPERTY(text, NSString) HIPPY_EXPORT_SHADOW_PROPERTY(autoLetterSpacing, BOOL) -- (HippyViewManagerUIBlock)uiBlockToAmendWithRenderObjectRegistry:(NSDictionary *)renderObjectRegistry { +- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary *)renderObjectRegistry { for (HippyShadowView *rootView in renderObjectRegistry.allValues) { if (![rootView isHippyRootView]) { // This isn't a root view @@ -123,7 +123,7 @@ - (HippyViewManagerUIBlock)uiBlockToAmendWithRenderObjectRegistry:(NSDictionary< return nil; } -- (HippyViewManagerUIBlock)uiBlockToAmendWithHippyShadowView:(NativeRenderObjectText *)renderObjectText { +- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowView:(NativeRenderObjectText *)renderObjectText { NSNumber *componentTag = renderObjectText.hippyTag; UIEdgeInsets padding = renderObjectText.paddingAsInsets; diff --git a/renderer/native/ios/renderer/component/textinput/NativeRenderTextView.mm b/renderer/native/ios/renderer/component/textinput/NativeRenderTextView.mm index 204c437df5f..1d0e9a321e6 100644 --- a/renderer/native/ios/renderer/component/textinput/NativeRenderTextView.mm +++ b/renderer/native/ios/renderer/component/textinput/NativeRenderTextView.mm @@ -159,7 +159,7 @@ - (void)didUpdateHippySubviews { - (void)setMostRecentEventCount:(NSInteger)mostRecentEventCount { _mostRecentEventCount = mostRecentEventCount; - // Props are set after uiBlockToAmendWithRenderObjectRegistry, which means that + // Props are set after uiBlockToAmendWithShadowViewRegistry, which means that // at the time performTextUpdate is called, _mostRecentEventCount will be // behind _eventCount, with the result that performPendingTextUpdate will do // nothing. For that reason we call it again here after mostRecentEventCount diff --git a/renderer/native/ios/renderer/component/textinput/NativeRenderTextViewManager.mm b/renderer/native/ios/renderer/component/textinput/NativeRenderTextViewManager.mm index ddfca2ae1bb..69ea4705707 100644 --- a/renderer/native/ios/renderer/component/textinput/NativeRenderTextViewManager.mm +++ b/renderer/native/ios/renderer/component/textinput/NativeRenderTextViewManager.mm @@ -75,7 +75,7 @@ - (HippyShadowView *)hippyShadowView { HIPPY_EXPORT_VIEW_PROPERTY(isNightMode, BOOL) HIPPY_EXPORT_METHOD(focusTextInput:(nonnull NSNumber *)componentTag) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ NativeRenderBaseTextInput *view = (NativeRenderBaseTextInput *)viewRegistry[componentTag]; if (view == nil) return ; if (![view isKindOfClass:[NativeRenderBaseTextInput class]]) { @@ -86,7 +86,7 @@ - (HippyShadowView *)hippyShadowView { } HIPPY_EXPORT_METHOD(isFocused:(nonnull NSNumber *)componentTag callback:(HippyPromiseResolveBlock)callback) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderBaseTextInput *view = (NativeRenderBaseTextInput *)viewRegistry[componentTag]; if (view == nil) return ; if (![view isKindOfClass:[NativeRenderBaseTextInput class]]) { @@ -98,7 +98,7 @@ - (HippyShadowView *)hippyShadowView { } HIPPY_EXPORT_METHOD(blurTextInput:(nonnull NSNumber *)componentTag) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ NativeRenderBaseTextInput *view = (NativeRenderBaseTextInput *)viewRegistry[componentTag]; if (view == nil) return ; if (![view isKindOfClass:[NativeRenderBaseTextInput class]]) { @@ -109,7 +109,7 @@ - (HippyShadowView *)hippyShadowView { } HIPPY_EXPORT_METHOD(clear:(nonnull NSNumber *)componentTag) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderBaseTextInput *view = (NativeRenderBaseTextInput *)viewRegistry[componentTag]; if (view == nil) return ; if (![view isKindOfClass:[NativeRenderBaseTextInput class]]) { @@ -121,7 +121,7 @@ - (HippyShadowView *)hippyShadowView { HIPPY_EXPORT_METHOD(setValue:(nonnull NSNumber *)componentTag text:(NSString *)text ) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderBaseTextInput *view = (NativeRenderBaseTextInput *)viewRegistry[componentTag]; if (view == nil) return ; if (![view isKindOfClass:[NativeRenderBaseTextInput class]]) { @@ -133,7 +133,7 @@ - (HippyShadowView *)hippyShadowView { HIPPY_EXPORT_METHOD(getValue:(nonnull NSNumber *)componentTag callback:(HippyPromiseResolveBlock)callback ) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderBaseTextInput *view = (NativeRenderBaseTextInput *)viewRegistry[componentTag]; NSString *stringValue = [view value]; if (nil == stringValue) { @@ -202,7 +202,7 @@ - (HippyShadowView *)hippyShadowView { view.font = [HippyFont updateFont:view.font withFamily:json ?: defaultView.font.familyName]; } -- (HippyViewManagerUIBlock)uiBlockToAmendWithHippyShadowView:(HippyShadowView *)hippyShadowView { +- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowView:(HippyShadowView *)hippyShadowView { NSNumber *componentTag = hippyShadowView.hippyTag; UIEdgeInsets padding = hippyShadowView.paddingAsInsets; return ^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { diff --git a/renderer/native/ios/renderer/component/view/HippyViewManager.h b/renderer/native/ios/renderer/component/view/HippyViewManager.h index 62a4019d95c..5e5a6f166f8 100644 --- a/renderer/native/ios/renderer/component/view/HippyViewManager.h +++ b/renderer/native/ios/renderer/component/view/HippyViewManager.h @@ -25,12 +25,17 @@ #import "NativeRenderDefines.h" #import "HippyBridgeModule.h" +@class HippyBridge; @class HippyShadowView; -@class HippyUIManager; @interface HippyViewManager : NSObject -@property(nonatomic, weak)HippyUIManager *renderImpl; +/** + * The bridge can be used to access both the HippyUIIManager and the HippyEventDispatcher, + * allowing the manager (or the views that it manages) to manipulate the view + * hierarchy and send events back to the JS context. + */ +@property (nonatomic, weak) HippyBridge *bridge; /** * This method instantiates a native view to be managed by the module. Override @@ -53,7 +58,7 @@ * Called to notify manager that layout has finished, in case any calculated * properties need to be copied over from shadow view to view. */ -- (HippyViewManagerUIBlock)uiBlockToAmendWithHippyShadowView:(HippyShadowView *)renderObject; +- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowView:(HippyShadowView *)shadowView; /** * Called after view hierarchy manipulation has finished, and all shadow props @@ -61,7 +66,7 @@ * custom layout logic or tasks that involve walking the view hierarchy. * To be deprecated, hopefully. */ -- (HippyViewManagerUIBlock)uiBlockToAmendWithRenderObjectRegistry:(NSDictionary *)renderObjectRegistry; +- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary *)shadowViewRegistry; /** * This handles the simple case, where JS and native property names match. @@ -119,3 +124,9 @@ @interface HippyViewManager (InitProps) @property (nonatomic, strong) NSDictionary *props; @end + +@interface HippyViewManager (UIManager) + +@property (nonatomic, strong) HippyUIManager *uiManager; + +@end diff --git a/renderer/native/ios/renderer/component/view/HippyViewManager.mm b/renderer/native/ios/renderer/component/view/HippyViewManager.mm index ec396711b38..1dfa9235366 100644 --- a/renderer/native/ios/renderer/component/view/HippyViewManager.mm +++ b/renderer/native/ios/renderer/component/view/HippyViewManager.mm @@ -33,19 +33,20 @@ #import "UIView+DirectionalLayout.h" #import "UIView+Hippy.h" #import "HippyBridgeModule.h" -#include -#include "VFSUriLoader.h" -#include "dom/layout_node.h" +#import +#import "VFSUriLoader.h" +#import "dom/layout_node.h" @interface HippyViewManager () { NSUInteger _sequence; - __weak HippyUIManager *_renderImpl; } @end @implementation HippyViewManager +@synthesize bridge = _bridge; + HIPPY_EXPORT_MODULE(View); - (UIView *)view { @@ -56,24 +57,20 @@ - (HippyShadowView *)hippyShadowView { return [[HippyShadowView alloc] init]; } -- (HippyViewManagerUIBlock)uiBlockToAmendWithHippyShadowView:(__unused HippyShadowView *)renderObject { +- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowView:(__unused HippyShadowView *)shadowView { return nil; } -- (HippyViewManagerUIBlock)uiBlockToAmendWithRenderObjectRegistry:(__unused NSDictionary *)renderObjectRegistry { +- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDictionary *)shadowViewRegistry { return nil; } -- (HippyUIManager *)renderImpl { - return _renderImpl; -} - -static NSString * const NativeRenderViewManagerGetBoundingRelToContainerKey = @"relToContainer"; -static NSString * const NativeRenderViewManagerGetBoundingErrMsgrKey = @"errMsg"; +static NSString * const HippyViewManagerGetBoundingRelToContainerKey = @"relToContainer"; +static NSString * const HippyViewManagerGetBoundingErrMsgrKey = @"errMsg"; HIPPY_EXPORT_METHOD(getBoundingClientRect:(nonnull NSNumber *)hippyTag - options:(nullable NSDictionary *)options - callback:(HippyPromiseResolveBlock)callback ) { - if (options && [[options objectForKey:NativeRenderViewManagerGetBoundingRelToContainerKey] boolValue]) { + options:(nullable NSDictionary *)options + callback:(HippyPromiseResolveBlock)callback ) { + if (options && [[options objectForKey:HippyViewManagerGetBoundingRelToContainerKey] boolValue]) { [self measureInWindow:hippyTag withErrMsg:YES callback:callback]; } else { [self measureInAppWindow:hippyTag withErrMsg:YES callback:callback]; @@ -81,21 +78,21 @@ - (HippyUIManager *)renderImpl { } HIPPY_EXPORT_METHOD(measureInWindow:(NSNumber *)componentTag - callback:(HippyPromiseResolveBlock)callback) { + callback:(HippyPromiseResolveBlock)callback) { [self measureInWindow:componentTag withErrMsg:NO callback:callback]; } - (void)measureInWindow:(NSNumber *)componentTag withErrMsg:(BOOL)withErrMsg callback:(HippyPromiseResolveBlock)callback { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { UIView *view = viewRegistry[componentTag]; if (!view) { if (withErrMsg) { NSString *formatStr = @"measure cannot find view with tag #%@"; NSString *errMsg = [NSString stringWithFormat:formatStr, componentTag]; - callback(@{NativeRenderViewManagerGetBoundingErrMsgrKey : errMsg}); + callback(@{HippyViewManagerGetBoundingErrMsgrKey : errMsg}); } else { callback(@{}); } @@ -106,7 +103,7 @@ - (void)measureInWindow:(NSNumber *)componentTag if (withErrMsg) { NSString *formatStr = @"measure cannot find view's root view with tag #%@"; NSString *errMsg = [NSString stringWithFormat:formatStr, componentTag]; - callback(@{NativeRenderViewManagerGetBoundingErrMsgrKey : errMsg}); + callback(@{HippyViewManagerGetBoundingErrMsgrKey : errMsg}); } else { callback(@{}); } @@ -128,7 +125,7 @@ - (void)measureInWindow:(NSNumber *)componentTag - (void)measureInAppWindow:(NSNumber *)componentTag withErrMsg:(BOOL)withErrMsg callback:(HippyPromiseResolveBlock)callback { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { UIView *view = viewRegistry[componentTag]; if (!view) { @@ -146,7 +143,7 @@ - (void)measureInAppWindow:(NSNumber *)componentTag HIPPY_EXPORT_METHOD(getScreenShot:(nonnull NSNumber *)componentTag params:(NSDictionary *__nonnull)params callback:(HippyPromiseResolveBlock)callback) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { UIView *view = viewRegistry[componentTag]; if (view == nil) { callback(@[]); @@ -186,7 +183,7 @@ - (void)measureInAppWindow:(NSNumber *)componentTag HIPPY_EXPORT_METHOD(getLocationOnScreen:(nonnull NSNumber *)componentTag params:(NSDictionary *__nonnull)params callback:(HippyPromiseResolveBlock)callback) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { UIView *view = viewRegistry[componentTag]; if (view == nil) { callback(@[]); @@ -244,12 +241,14 @@ - (void)loadImageSource:(NSString *)path forView:(HippyView *)view { } NSString *standardizeAssetUrlString = path; __weak HippyView *weakView = view; - auto loader = [[self renderImpl] VFSUriLoader].lock(); + auto loader = [self.bridge.uiManager VFSUriLoader].lock(); if (!loader) { return; } + __weak __typeof(self)weakSelf = self; loader->RequestUntrustedContent(path, nil, nil, ^(NSData *data, NSURLResponse *response, NSError *error) { - HippyUIManager *renderImpl = self.renderImpl; + __strong __typeof(weakSelf)strongSelf = weakSelf; + HippyUIManager *renderImpl = strongSelf.bridge.uiManager; id imageProvider = nil; if (renderImpl) { for (Class cls in [renderImpl imageProviderClasses]) { diff --git a/renderer/native/ios/renderer/component/viewPager/NativeRenderViewPagerManager.mm b/renderer/native/ios/renderer/component/viewPager/NativeRenderViewPagerManager.mm index e1f0b26a79f..95a18448dbc 100644 --- a/renderer/native/ios/renderer/component/viewPager/NativeRenderViewPagerManager.mm +++ b/renderer/native/ios/renderer/component/viewPager/NativeRenderViewPagerManager.mm @@ -42,7 +42,7 @@ - (UIView *)view { - (void)setPage:(NSNumber *)pageNumber withTag:(NSNumber * _Nonnull)componentTag animated:(BOOL)animated { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[componentTag]; if (![view isKindOfClass:[NativeRenderViewPager class]]) { diff --git a/renderer/native/ios/renderer/component/waterfalllist/NativeRenderWaterfallViewManager.mm b/renderer/native/ios/renderer/component/waterfalllist/NativeRenderWaterfallViewManager.mm index bf51ce7acd9..200f087feb6 100644 --- a/renderer/native/ios/renderer/component/waterfalllist/NativeRenderWaterfallViewManager.mm +++ b/renderer/native/ios/renderer/component/waterfalllist/NativeRenderWaterfallViewManager.mm @@ -58,7 +58,7 @@ - (HippyShadowView *)hippyShadowView { text:(nonnull NSString *)text duration:(nonnull NSNumber *)duration imageUrl:(nonnull NSString *)imageUrl) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderWaterfallView *view = (NativeRenderWaterfallView *)viewRegistry[reactTag]; if (view == nil) return; @@ -70,7 +70,7 @@ - (HippyShadowView *)hippyShadowView { } HIPPY_EXPORT_METHOD(startRefresh:(nonnull NSNumber *)reactTag) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderWaterfallView *view = (NativeRenderWaterfallView *)viewRegistry[reactTag]; if (view == nil) return; @@ -83,7 +83,7 @@ - (HippyShadowView *)hippyShadowView { HIPPY_EXPORT_METHOD(startRefreshWithType:(nonnull NSNumber *)reactTag type:(NSNumber *)type) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderWaterfallView *view = (NativeRenderWaterfallView *)viewRegistry[reactTag]; if (view == nil) return; @@ -95,7 +95,7 @@ - (HippyShadowView *)hippyShadowView { } HIPPY_EXPORT_METHOD(callExposureReport:(nonnull NSNumber *)reactTag) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderWaterfallView *view = (NativeRenderWaterfallView *)viewRegistry[reactTag]; if (view == nil) return; @@ -110,7 +110,7 @@ - (HippyShadowView *)hippyShadowView { xIndex:(nonnull NSNumber *)xIndex yIndex:(nonnull NSNumber *)yIndex animation:(nonnull NSNumber *)animation) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderWaterfallView *view = (NativeRenderWaterfallView *)viewRegistry[reactTag]; if (view == nil) return; @@ -125,7 +125,7 @@ - (HippyShadowView *)hippyShadowView { x:(nonnull NSNumber *)x y:(nonnull NSNumber *)y animation:(nonnull NSNumber *)animation) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderWaterfallView *view = (NativeRenderWaterfallView *)viewRegistry[reactTag]; if (view == nil) return; @@ -137,7 +137,7 @@ - (HippyShadowView *)hippyShadowView { } HIPPY_EXPORT_METHOD(startLoadMore:(nonnull NSNumber *)reactTag) { - [self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { NativeRenderWaterfallView *view = (NativeRenderWaterfallView *)viewRegistry[reactTag]; if (view == nil) return;