diff --git a/renderer/native/ios/renderer/HippyUIManager+Private.h b/renderer/native/ios/renderer/HippyUIManager+Private.h new file mode 100644 index 00000000000..67bfeff24b3 --- /dev/null +++ b/renderer/native/ios/renderer/HippyUIManager+Private.h @@ -0,0 +1,164 @@ +/*! + * iOS SDK + * + * Tencent is pleased to support the open source community by making + * Hippy available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HippyUIManager_Private_h +#define HippyUIManager_Private_h + +#include +#include +#include + +class VFSUriLoader; +namespace hippy { +inline namespace dom { +class RenderManager; +class DomManager; +class DomArgument; +class RootNode; +class DomNode; +struct LayoutResult; +using CallFunctionCallback = std::function)>; +} +} + +namespace footstone { +inline namespace value { +class HippyValue; +} +} + +@interface HippyUIManager (Private) + +- (void)registerRootView:(UIView *)rootView asRootNode:(std::weak_ptr)rootNode; + +- (void)unregisterRootViewFromTag:(NSNumber *)rootTag; + + +/** + * create views from dom nodes + * @param nodes A set of nodes for creating views + */ +- (void)createRenderNodes:(std::vector> &&)nodes + onRootNode:(std::weak_ptr)rootNode; + +/** + * update views' properties from dom nodes + * @param nodes A set of nodes for updating views' properties + */ +- (void)updateRenderNodes:(std::vector> &&)nodes + onRootNode:(std::weak_ptr)rootNode; + +/** + * delete views from dom nodes + * @param nodes nodes to delete + */ +- (void)deleteRenderNodesIds:(std::vector> &&)nodes + onRootNode:(std::weak_ptr)rootNode; + +/** + * move views from container to another container + * + * @param ids A set of nodes id to move + * @param fromContainer Source view container from which views move + * @param toContainer Target view container to which views move + */ +- (void)renderMoveViews:(const std::vector &&)ids + fromContainer:(int32_t)fromContainer + toContainer:(int32_t)toContainer + index:(int32_t)index + onRootNode:(std::weak_ptr)rootNode; + +- (void)renderMoveNodes:(std::vector> &&)nodes + onRootNode:(std::weak_ptr)rootNode; +/** + * update layout for view + * + * @param layoutInfos Vector for nodes layout infos + */ +- (void)updateNodesLayout:(const std::vector> &)layoutInfos + onRootNode:(std::weak_ptr)rootNode; + +/** + * call function of view + * + * @param functionName Function Name to be invoked + * @param viewName Name of target view whose function invokes + * @param hippyTag id of target view whose function invokes + * @param params parameters of function to be invoked + * @param cb A callback for the return value of function + * + * @result Function return result + */ +- (id)dispatchFunction:(const std::string &)functionName + viewName:(const std::string &)viewName + viewTag:(int32_t)hippyTag + onRootNode:(std::weak_ptr)rootNode + params:(const footstone::value::HippyValue &)params + callback:(hippy::CallFunctionCallback)cb; + + +/** + * set dom manager for NativeRenderUIManager which holds a weak reference to domManager + */ +- (void)setDomManager:(std::weak_ptr)domManager; + +/** + * Invoked after batched operations completed + */ +- (void)batchOnRootNode:(std::weak_ptr)rootNode; + +/** + * register event for specific view + * + * @param name event name + * @param node_id id for node for the event + */ +- (void)addEventName:(const std::string &)name + forDomNodeId:(int32_t)node_id + onRootNode:(std::weak_ptr)rootNode; + +/** + * unregister event for specific view + * + * @param name event name + * @param node_id node id for the event + */ +- (void)removeEventName:(const std::string &)name + forDomNodeId:(int32_t)node_id + onRootNode:(std::weak_ptr)rootNode; + +/** + * unregister vsync event + */ +- (void)removeVSyncEventOnRootNode:(std::weak_ptr)rootNode; + +/** + * Set root view size changed event callback + * + *@param cb callback + */ +- (void)setRootViewSizeChangedEvent:(std::function)cb; + + +@end + +#endif /* HippyUIManager_Private_h */ diff --git a/renderer/native/ios/renderer/HippyUIManager.h b/renderer/native/ios/renderer/HippyUIManager.h index 79a1df8e151..6c26f084c86 100644 --- a/renderer/native/ios/renderer/HippyUIManager.h +++ b/renderer/native/ios/renderer/HippyUIManager.h @@ -26,105 +26,79 @@ #import "NativeRenderDefines.h" #import "HippyBridgeModule.h" #import "HippyCustomTouchHandlerProtocol.h" -#include -#include -#include - -@class NativeRenderAnimationViewParams, HippyShadowView, HippyUIManager,HippyViewManager; -@class NativeRenderReusePool, HippyComponentMap; - -class VFSUriLoader; -namespace hippy { -inline namespace dom { -class RenderManager; -class DomManager; -class DomArgument; -class RootNode; -class DomNode; -struct LayoutResult; -using CallFunctionCallback = std::function)>; -} -} - -namespace footstone { -inline namespace value { -class HippyValue; -} -} +@class NativeRenderAnimationViewParams; +@class HippyShadowView; +@class HippyUIManager; +@class HippyViewManager; +@class NativeRenderReusePool; +@class HippyComponentMap; @protocol HippyImageProviderProtocol; -/** - * The NativeRenderUIManager is the module responsible for updating the view hierarchy. - */ + +/// The HippyUIManager responsible for updating the view hierarchy. @interface HippyUIManager : NSObject ++ (instancetype)new NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE; +#ifdef __cplusplus +/// Init method +/// - Parameter renderManager: the hippy::RenderManager - (instancetype)initWithRenderManager:(std::weak_ptr)renderManager NS_DESIGNATED_INITIALIZER; -@property(nonatomic, assign) BOOL uiCreationLazilyEnabled; - -@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; - -/** - * Gets the view associated with a hippyTag. - */ -- (UIView *)viewForHippyTag:(NSNumber *)hippyTag - onRootTag:(NSNumber *)rootTag; - - -/** - * Get the shadow view associated with a hippyTag - */ -- (HippyShadowView *)shadowViewForHippyTag:(NSNumber *)hippyTag - onRootTag:(NSNumber *)rootTag; +#endif -/** - * Update the frame of a view. This might be in response to a screen rotation - * or some other layout event outside of the Hippy-managed view hierarchy. - */ +@property (nonatomic, weak) HippyBridge *bridge; +@property (nonatomic, readonly) HippyComponentMap *viewRegistry; +@property (nonatomic, assign) BOOL uiCreationLazilyEnabled; + + +/// Gets the view associated with a hippyTag. +/// - Parameters: +/// - hippyTag: NSNumber +/// - rootTag: NSNumber +- (UIView *)viewForHippyTag:(NSNumber *)hippyTag onRootTag:(NSNumber *)rootTag; + +/// Get the shadow view associated with a hippyTag +/// - Parameters: +/// - hippyTag: NSNumber +/// - rootTag: NSNumber +- (HippyShadowView *)shadowViewForHippyTag:(NSNumber *)hippyTag onRootTag:(NSNumber *)rootTag; + +/// Update the frame of a view. This might be in response to a screen rotation +/// or some other layout event outside of the Hippy-managed view hierarchy. +/// - Parameters: +/// - frame: new frame +/// - view: target view - (void)setFrame:(CGRect)frame forRootView:(UIView *)view; -/** - * Schedule a block to be executed on the UI thread. Useful if you need to execute - * view logic after all currently queued view updates have completed. - */ +/// Schedule a block to be executed on the UI thread. Useful if you need to execute +/// view logic after all currently queued view updates have completed. +/// - Parameter block: block to be executed on main thread - (void)addUIBlock:(HippyViewManagerUIBlock)block; -/** - * In some cases we might want to trigger layout from native side. - * Hippy won't be aware of this, so we need to make sure it happens. - */ +/// In some cases we might want to trigger layout from native side. +/// Hippy won't be aware of this, so we need to make sure it happens. +/// - Parameter tag: root tag - (void)setNeedsLayoutForRootNodeTag:(NSNumber *)tag; -- (void)registerRootView:(UIView *)rootView asRootNode:(std::weak_ptr)rootNode; - -- (void)unregisterRootViewFromTag:(NSNumber *)rootTag; - +/// Get all rootView - (NSArray<__kindof UIView *> *)rootViews; -- (__kindof UIView *)viewFromRenderViewTag:(NSNumber *)componentTag onRootTag:(NSNumber *)rootTag; - +/// Purge view from superView - (void)purgeViewsFromComponentTags:(NSArray *)componentTag onRootTag:(NSNumber *)rootTag; +/// Update view with props - (void)updateView:(NSNumber *)componentTag onRootTag:(NSNumber *)rootTag props:(NSDictionary *)pros; +/// Get viewManager Name +/// @param viewName NSString - (__kindof HippyViewManager *)renderViewManagerForViewName:(NSString *)viewName; -/** - * Manully create views recursively from hippy tag - * - * @param hippyTag hippy tag corresponding to UIView - * @return view created by hippy tag - */ -- (UIView *)createViewRecursivelyFromcomponentTag:(NSNumber *)hippyTag - onRootTag:(NSNumber *)rootTag; - /** * Manully create views recursively from renderObject * @@ -133,126 +107,18 @@ class HippyValue; */ - (UIView *)createViewRecursivelyFromRenderObject:(HippyShadowView *)renderObject; -/** - * set dom manager for NativeRenderUIManager which holds a weak reference to domManager - */ -- (void)setDomManager:(std::weak_ptr)domManager; - -/** - * create views from dom nodes - * @param nodes A set of nodes for creating views - */ -- (void)createRenderNodes:(std::vector> &&)nodes - onRootNode:(std::weak_ptr)rootNode; - -/** - * update views' properties from dom nodes - * @param nodes A set of nodes for updating views' properties - */ -- (void)updateRenderNodes:(std::vector> &&)nodes - onRootNode:(std::weak_ptr)rootNode; - -/** - * delete views from dom nodes - * @param nodes nodes to delete - */ -- (void)deleteRenderNodesIds:(std::vector> &&)nodes - onRootNode:(std::weak_ptr)rootNode; - -/** - * move views from container to another container - * - * @param ids A set of nodes id to move - * @param fromContainer Source view container from which views move - * @param toContainer Target view container to which views move - */ -- (void)renderMoveViews:(const std::vector &&)ids - fromContainer:(int32_t)fromContainer - toContainer:(int32_t)toContainer - index:(int32_t)index - onRootNode:(std::weak_ptr)rootNode; - -- (void)renderMoveNodes:(std::vector> &&)nodes - onRootNode:(std::weak_ptr)rootNode; -/** - * update layout for view - * - * @param layoutInfos Vector for nodes layout infos - */ -- (void)updateNodesLayout:(const std::vector> &)layoutInfos - onRootNode:(std::weak_ptr)rootNode; - -/** - * Invoked after batched operations completed - */ -- (void)batchOnRootNode:(std::weak_ptr)rootNode; - -/** - * call function of view - * - * @param functionName Function Name to be invoked - * @param viewName Name of target view whose function invokes - * @param hippyTag id of target view whose function invokes - * @param params parameters of function to be invoked - * @param cb A callback for the return value of function - * - * @result Function return result - */ -- (id)dispatchFunction:(const std::string &)functionName - viewName:(const std::string &)viewName - viewTag:(int32_t)hippyTag - onRootNode:(std::weak_ptr)rootNode - params:(const footstone::value::HippyValue &)params - callback:(hippy::CallFunctionCallback)cb; - +/// Register extra components +/// @param extraComponents extra components classes - (void)registerExtraComponent:(NSArray *)extraComponents; -/** - * register event for specific view - * - * @param name event name - * @param node_id id for node for the event - */ -- (void)addEventName:(const std::string &)name - forDomNodeId:(int32_t)node_id - onRootNode:(std::weak_ptr)rootNode; - -/** - * unregister event for specific view - * - * @param name event name - * @param node_id node id for the event - */ -- (void)removeEventName:(const std::string &)name - forDomNodeId:(int32_t)node_id - onRootNode:(std::weak_ptr)rootNode; - -/** - * unregister vsync event - */ -- (void)removeVSyncEventOnRootNode:(std::weak_ptr)rootNode; - -/** - * Set root view size changed event callback - * - *@param cb callback - */ -- (void)setRootViewSizeChangedEvent:(std::function)cb; - -/** - * clear all resources - */ +/// Clear all resources - (void)invalidate; -#if HIPPY_DEBUG -@property(nonatomic, assign) std::unordered_map>> domNodesMap; -- (std::shared_ptr)domNodeForTag:(int32_t)dom_tag onRootNode:(int32_t)root_tag; -- (std::vector>)childrenForNodeTag:(int32_t)tag onRootNode:(int32_t)root_tag; -#endif - @end +#pragma mark - HippyBridge (HippyUIManager) + /** * This category makes the current HippyUIManager instance available via the * HippyBridge, which is useful for HippyBridgeModules or HippyViewManagers that diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 33b55409be1..5c2da165fe9 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -31,6 +31,7 @@ #import "HippyComponentData.h" #import "HippyComponentMap.h" #import "HippyUIManager.h" +#import "HippyUIManager+Private.h" #import "NativeRenderObjectRootView.h" #import "HippyShadowView.h" #import "NativeRenderUtils.h" @@ -46,6 +47,7 @@ #import "NativeRenderManager.h" #include "dom/root_node.h" #include "objc/runtime.h" +#include using HippyValue = footstone::value::HippyValue; using DomArgument = hippy::dom::DomArgument; @@ -184,6 +186,12 @@ @interface HippyUIManager() { std::function _rootViewSizeChangedCb; } +#if HIPPY_DEBUG +@property(nonatomic, assign) std::unordered_map>> domNodesMap; +- (std::shared_ptr)domNodeForTag:(int32_t)dom_tag onRootNode:(int32_t)root_tag; +- (std::vector>)childrenForNodeTag:(int32_t)tag onRootNode:(int32_t)root_tag; +#endif + @end @implementation HippyUIManager @@ -458,12 +466,6 @@ - (void)removeChildren:(NSArray> *)children fromContainer:(id } } -- (UIView *)createViewRecursivelyFromcomponentTag:(NSNumber *)componentTag - onRootTag:(NSNumber *)rootTag { - HippyShadowView *renderObject = [_shadowViewRegistry componentForTag:componentTag onRootTag:rootTag]; - return [self createViewRecursivelyFromRenderObject:renderObject]; -} - - (UIView *)createViewFromRenderObject:(HippyShadowView *)renderObject { AssertMainQueue(); HippyAssert(renderObject.viewName, @"view name is needed for creating a view"); diff --git a/renderer/native/ios/renderer/NativeRenderManager.mm b/renderer/native/ios/renderer/NativeRenderManager.mm index 10ba338ae5b..9e34a009df5 100644 --- a/renderer/native/ios/renderer/NativeRenderManager.mm +++ b/renderer/native/ios/renderer/NativeRenderManager.mm @@ -21,6 +21,7 @@ */ #import "HippyUIManager.h" +#import "HippyUIManager+Private.h" #import "NativeRenderManager.h" #import "NativeRenderObjectText.h" #import "RenderVsyncManager.h" diff --git a/renderer/native/ios/renderer/component/listview/NativeRenderBaseListView.mm b/renderer/native/ios/renderer/component/listview/NativeRenderBaseListView.mm index 2c617ce7cd2..f64f5aabc98 100644 --- a/renderer/native/ios/renderer/component/listview/NativeRenderBaseListView.mm +++ b/renderer/native/ios/renderer/component/listview/NativeRenderBaseListView.mm @@ -259,7 +259,7 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView forIndexPath:indexPath]; HippyShadowView *headerRenderObject = [self.dataSource headerForSection:section]; if (headerRenderObject && [headerRenderObject isKindOfClass:[HippyShadowView class]]) { - UIView *headerView = [self.renderImpl viewFromRenderViewTag:headerRenderObject.hippyTag onRootTag:headerRenderObject.rootTag]; + UIView *headerView = [self.renderImpl viewForHippyTag:headerRenderObject.hippyTag onRootTag:headerRenderObject.rootTag]; if (!headerView) { headerView = [self.renderImpl createViewRecursivelyFromRenderObject:headerRenderObject]; }