Skip to content

Commit

Permalink
refactor(ios): Revert rename Hippy prefix to NativeRender part 11
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Oct 10, 2023
1 parent 5572b13 commit 6d7e675
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 81 deletions.
6 changes: 3 additions & 3 deletions docs/development/native-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ - (void)setUpNativeRenderManager {
_nativeRenderManager->AddImageProviderClass([HippyDefaultImageProvider class]);
_nativeRenderManager->RegisterExtraComponent(_extraComponents);
_nativeRenderManager->SetVFSUriLoader([self URILoader]);
_nativeRenderManager->SetHippyBridge(self.bridge);
_bridge.renderManager = _nativeRenderManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ @implementation MyViewManager

HIPPY_EXPORT_METHOD(changeColor:(nonnull NSNumber *)reactTag
color:(NSString *)color) {
[self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
[self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[reactTag];
if (view == nil || ![view isKindOfClass:[MyView class]]) {
HippyLogError(@"tried to setPage: on an error viewPager %@ "
Expand Down
4 changes: 2 additions & 2 deletions renderer/native/ios/renderer/HippyComponentData.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -511,7 +511,7 @@ - (NSString *)selectorStringFromSignature:(NSString *)signature {

- (HippyViewManagerUIBlock)uiBlockToAmendWithRenderObjectViewRegistry:(NSDictionary<NSNumber *, HippyShadowView *> *)registry {
if (_implementsUIBlockToAmendWithRenderObjectRegistry) {
return [[self manager] uiBlockToAmendWithRenderObjectRegistry:registry];
return [[self manager] uiBlockToAmendWithShadowViewRegistry:registry];
}
return nil;
}
Expand Down
28 changes: 21 additions & 7 deletions renderer/native/ios/renderer/HippyUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

#import <UIKit/UIKit.h>

#import "HippyBridge.h"
#import "HippyInvalidating.h"
#import "NativeRenderDefines.h"
#import "HippyBridgeModule.h"
Expand Down Expand Up @@ -64,10 +64,11 @@ class HippyValue;

@property(nonatomic, assign) BOOL uiCreationLazilyEnabled;

@property(nonatomic, assign) std::weak_ptr<VFSUriLoader> VFSUriLoader;
@property(nonatomic, assign) std::weak_ptr<hippy::RenderManager> renderManager;
@property(nonatomic, readonly) std::weak_ptr<hippy::DomManager> domManager;
@property(nonatomic, readonly) HippyComponentMap *viewRegistry;
@property (nonatomic, weak) HippyBridge *bridge;
@property (nonatomic, assign) std::weak_ptr<VFSUriLoader> VFSUriLoader;
@property (nonatomic, assign) std::weak_ptr<hippy::RenderManager> renderManager;
@property (nonatomic, readonly) std::weak_ptr<hippy::DomManager> domManager;
@property (nonatomic, readonly) HippyComponentMap *viewRegistry;

- (void)addImageProviderClass:(Class<HippyImageProviderProtocol>)cls;
- (NSArray<Class<HippyImageProviderProtocol>> *)imageProviderClasses;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<hippy::RootNode>)rootNode
params:(const footstone::value::HippyValue &)params
callback:(hippy::CallFunctionCallback)cb;
Expand Down Expand Up @@ -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
21 changes: 19 additions & 2 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<NativeRenderManager>(renderManager);
return nativeRenderManager->GetHippyUIManager();
}
return nil;
}
@end
7 changes: 7 additions & 0 deletions renderer/native/ios/renderer/NativeRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ class NativeRenderManager : public hippy::RenderManager ,public std::enable_shar
*@param loader vfs url loader instance
*/
void SetVFSUriLoader(std::shared_ptr<VFSUriLoader> loader);

/**
* Set HippyBridge pointer to renderManager
*
*@param bridge HippyBridge instance
*/
void SetHippyBridge(HippyBridge *bridge);

/**
* Set root view size changed event callback
Expand Down
5 changes: 5 additions & 0 deletions renderer/native/ios/renderer/NativeRenderManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(int32_t rootTag, NSDictionary *)> cb) {
[renderImpl_ setRootViewSizeChangedEvent:cb];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSNumber *, __kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
HippyRefresh *refreshView = viewRegistry[reactTag];
[refreshView refreshFinish];
}];
}

HIPPY_EXPORT_METHOD(collapsePullFooterWithOptions:(nonnull NSNumber *)reactTag options:(NSDictionary *)options) {
[self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
HippyRefresh *refreshView = viewRegistry[reactTag];
[refreshView refreshFinishWithOption:options];
}];
}

HIPPY_EXPORT_METHOD(expandPullFooter:(nonnull NSNumber *)reactTag) {
[self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
HippyRefresh *refreshView = viewRegistry[reactTag];
[refreshView refresh];
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSNumber *, __kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
HippyRefresh *refreshView = viewRegistry[reactTag];
[refreshView refresh];
}];
}

HIPPY_EXPORT_METHOD(collapsePullHeader:(nonnull NSNumber *)reactTag) {
[self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
HippyRefresh *refreshView = viewRegistry[reactTag];
[refreshView refreshFinish];
}];
}

HIPPY_EXPORT_METHOD(collapsePullHeaderWithOptions:(nonnull NSNumber *)reactTag options:(NSDictionary *)options) {
[self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *, __kindof UIView *> *viewRegistry) {
HippyRefresh *refreshView = viewRegistry[reactTag];
[refreshView refreshFinishWithOption:options];
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HippyImageProviderProtocol> imageProvider = nil;
if (renderImpl) {
for (Class<HippyImageProviderProtocol> cls in [renderImpl imageProviderClasses]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSNumber *, UIView *> *viewRegistry){
NativeRenderBaseListView *view = (NativeRenderBaseListView *)viewRegistry[componentTag];
if (view == nil) return ;
Expand All @@ -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<NSNumber *, UIView *> *viewRegistry){
NativeRenderBaseListView *view = (NativeRenderBaseListView *)viewRegistry[componentTag];
if (view == nil) return ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ - (UIView *)view {
}

HIPPY_EXPORT_METHOD(push:(NSNumber *__nonnull)componentTag parms:(NSDictionary *__nonnull)params) {
[self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *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<NSNumber *,__kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
NativeRenderNavigatorHostView *navigatorHostView = viewRegistry[componentTag];
[navigatorHostView pop:params];
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ - (UIView *)view {
}

HIPPY_EXPORT_METHOD(refreshComplected:(NSNumber *__nonnull)componentTag) {
[self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
NativeRenderRefreshWrapper *wrapperView = viewRegistry[componentTag];
[wrapperView refreshCompleted];
}];
}

HIPPY_EXPORT_METHOD(startRefresh:(NSNumber *__nonnull)componentTag) {
[self.renderImpl addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
NativeRenderRefreshWrapper *wrapperView = viewRegistry[componentTag];
[wrapperView startRefresh];
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ - (UIView *)view {

HIPPY_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)componentTag
callback:(HippyPromiseResolveBlock)callback) {
[self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
HippyScrollView *view = viewRegistry[componentTag];
CGSize size = view.scrollView.contentSize;
callback(@{@"width" : @(size.width),@"height" : @(size.height)});
Expand All @@ -111,7 +111,7 @@ - (UIView *)view {
offsetX:(NSNumber *)x
offsetY:(NSNumber *)y
animated:(NSNumber *)animated) {
[self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
[self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[componentTag];
if (view == nil) return ;
if ([view conformsToProtocol:@protocol(HippyScrollableProtocol)]) {
Expand All @@ -125,7 +125,7 @@ - (UIView *)view {

HIPPY_EXPORT_METHOD(scrollToWithOptions:(nonnull NSNumber *)componentTag
options:(NSDictionary *)options) {
[self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
[self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[componentTag];
if (view == nil) return ;
if ([view conformsToProtocol:@protocol(HippyScrollableProtocol)]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (UIView *)view {

HIPPY_EXPORT_METHOD(setPage:(nonnull NSNumber *)componentTag
pageNumber:(NSNumber *)pageNumber) {
[self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
[self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[componentTag];

if (view == nil || ![view isKindOfClass:[NativeRenderSmartViewPagerView class]]) {
Expand All @@ -64,7 +64,7 @@ - (UIView *)view {

HIPPY_EXPORT_METHOD(setPageWithoutAnimation:(nonnull NSNumber *)componentTag
pageNumber:(NSNumber *)pageNumber) {
[self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
[self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[componentTag];
if (view == nil || ![view isKindOfClass:[NativeRenderSmartViewPagerView class]]) {
HippyLogError(@"tried to setPage: on an error viewPager %@ "
Expand All @@ -77,7 +77,7 @@ - (UIView *)view {

HIPPY_EXPORT_METHOD(getPageIndex:(nonnull NSNumber *)componentTag
callback:(HippyPromiseResolveBlock)callback) {
[self.renderImpl addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
[self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
NativeRenderSmartViewPagerView *view = viewRegistry[componentTag];
NSInteger currrentPage = [view getCurrentPage];
callback(@(currrentPage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ - (HippyShadowView *)hippyShadowView {
HIPPY_EXPORT_SHADOW_PROPERTY(text, NSString)
HIPPY_EXPORT_SHADOW_PROPERTY(autoLetterSpacing, BOOL)

- (HippyViewManagerUIBlock)uiBlockToAmendWithRenderObjectRegistry:(NSDictionary<NSNumber *, HippyShadowView *> *)renderObjectRegistry {
- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NSNumber *, HippyShadowView *> *)renderObjectRegistry {
for (HippyShadowView *rootView in renderObjectRegistry.allValues) {
if (![rootView isHippyRootView]) {
// This isn't a root view
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 6d7e675

Please sign in to comment.