diff --git a/framework/examples/ios-demo/podfile b/framework/examples/ios-demo/podfile index 9fcf344c618..f2f919f869c 100644 --- a/framework/examples/ios-demo/podfile +++ b/framework/examples/ios-demo/podfile @@ -1,4 +1,4 @@ -ENV["layout_engine"]="Taitank" +# ENV["layout_engine"]="Taitank" # ENV["js_engine"] = "v8" install! 'cocoapods', :deterministic_uuids => false, @@ -38,4 +38,4 @@ post_install do |installer| #change search path for HippyDemo rewriteConfigFile("#{_pod_debug_config_dir_}", "${PODS_ROOT}/hippy", "#{_hippy_dir_}") rewriteConfigFile("#{_pod_release_config_dir_}", "${PODS_ROOT}/hippy", "#{_hippy_dir_}") -end \ No newline at end of file +end diff --git a/framework/ios/base/HippyDeviceBaseInfo.h b/framework/ios/base/HippyDeviceBaseInfo.h index 0c26f149716..4a8bb80f49f 100644 --- a/framework/ios/base/HippyDeviceBaseInfo.h +++ b/framework/ios/base/HippyDeviceBaseInfo.h @@ -25,10 +25,15 @@ NS_ASSUME_NONNULL_BEGIN -HIPPY_EXTERN NSDictionary *HippyExportedDimensions(void); +HIPPY_EXTERN NSDictionary *hippyExportedDimensions(HippyBridge *); +HIPPY_EXTERN NSString *const HippyDimensionsShouldUpdateNotification; +/// A Helper class that collects `Dimensions` info @interface HippyDeviceBaseInfo : NSObject +/// Whether is UIScreen in system dark mode. ++ (BOOL)isUIScreenInOSDarkMode; + @end NS_ASSUME_NONNULL_END diff --git a/framework/ios/base/HippyDeviceBaseInfo.mm b/framework/ios/base/HippyDeviceBaseInfo.mm index 8abc59860a5..3e7fbcd18e9 100644 --- a/framework/ios/base/HippyDeviceBaseInfo.mm +++ b/framework/ios/base/HippyDeviceBaseInfo.mm @@ -21,53 +21,40 @@ */ #import - #import "HippyAsserts.h" #import "HippyUtils.h" #import "HippyDeviceBaseInfo.h" #import "HippyEventDispatcher.h" -static BOOL IsiPhoneX() { - if (@available(iOS 11.0, *)) { - CGFloat height = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom; - return (height > 0); - } else { - return NO; - } -} - -static NSDictionary *gDimensions = nil; -static dispatch_semaphore_t DimesionSemaphore(void) { - static dispatch_semaphore_t semaphore = nil; +NSDictionary *hippyExportedDimensions(HippyBridge *bridge) { + NSCAssert([NSThread mainThread], @"this function can only be called in main thread"); + CGSize screenSize = [UIScreen mainScreen].bounds.size; + CGSize windowSize = HippyKeyWindow() ? HippyKeyWindow().bounds.size : screenSize; + // To be replace by HippyKeyWindow().windowScene.statusBarManager.statusBarFrame; + CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height; + if (statusBarHeight == 0) { + // Since different devices have different statusbar height values, + // It is not recommended to use it for layout, + // but, it has been used in some scenarios, + // To reduce the impact of the problem, provide a default value when not available. + if ([bridge.delegate respondsToSelector:@selector(defaultStatusBarHeightNoMatterHiddenOrNot)]) { + statusBarHeight = bridge.delegate.defaultStatusBarHeightNoMatterHiddenOrNot ?: 0.0; + } + } + static NSNumber *screenScale = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - semaphore = dispatch_semaphore_create(1); - }); - return semaphore; -} - -static NSDictionary *InitializeDimesions(void) { - __block CGSize screenSize = CGSizeZero; - __block CGSize windowSize = CGSizeZero; - __block CGFloat statusBarHeight = 0.f; - __block NSNumber *screenScale = nil; - - dispatch_block_t block = ^(void){ - screenSize = [UIScreen mainScreen].bounds.size; - windowSize = HippyKeyWindow() ? HippyKeyWindow().bounds.size : screenSize; - statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height; - if (statusBarHeight == 0) { - statusBarHeight = IsiPhoneX() ? 44 : 20; - } screenScale = @([UIScreen mainScreen].scale); - }; - HippyExecuteOnMainThread(block, YES); - gDimensions = @{ - // 备注,window和screen的区别在于有没有底bar虚拟导航栏,而iOS没有这个东西,所以window和screen是一样的 - @"window": - @ { @"width": @(windowSize.width), @"height": @(windowSize.height), @"scale": screenScale, @"statusBarHeight": @(statusBarHeight) }, - @"screen": @ { + }); + NSDictionary *dimensions = @{ + @"window" : @{ + @"width": @(windowSize.width), + @"height": @(windowSize.height), + @"scale": screenScale, + @"statusBarHeight": @(statusBarHeight) + }, + @"screen" : @{ @"width": @(screenSize.width), @"height": @(screenSize.height), @"scale": screenScale, @@ -75,113 +62,96 @@ static dispatch_semaphore_t DimesionSemaphore(void) { @"statusBarHeight": @(statusBarHeight) } }; - return gDimensions; -} - -static void DisposeDimesions(void) { - dispatch_semaphore_wait(DimesionSemaphore(), DISPATCH_TIME_FOREVER); - gDimensions = nil; - dispatch_semaphore_signal(DimesionSemaphore()); -} - -NSDictionary *HippyExportedDimensions(void) { - NSDictionary *dic = nil; - dispatch_semaphore_wait(DimesionSemaphore(), DISPATCH_TIME_FOREVER); - if (gDimensions) { - dic = [gDimensions copy]; - } - else { - dic = [InitializeDimesions() copy]; - } - dispatch_semaphore_signal(DimesionSemaphore()); - return dic; + return dimensions; } -@protocol HippyStatusBarOrientationChangedProtocol -@required -- (void)statusBarOrientationChanged; -@end +#pragma mark - -@interface HippyBaseInfoInternal : NSObject { - NSHashTable> *_observers; +@interface HippyDeviceBaseInfo () { + id _statusBarOrientationNotificationObserver; + id _applicationDidBecomeActiveNotificationObserver; + UIInterfaceOrientation _currentInterfaceOrientation; } -+ (instancetype)sharedInstance; +@end -- (void)addObserver:(id)observer; +@implementation HippyDeviceBaseInfo -- (void)removeObserver:(id)observer; +HIPPY_EXPORT_MODULE(DeviceBaseInfo) -@end +NSString *const HippyDimensionsShouldUpdateNotification = @"HippyDimensionsShouldUpdateNotification"; -@implementation HippyBaseInfoInternal +@synthesize bridge = _bridge; -+ (instancetype)sharedInstance { - static HippyBaseInfoInternal *instance = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - instance = [[HippyBaseInfoInternal alloc] init]; - }); - return instance; +static UIInterfaceOrientation getStatusBarOrientation(void) { + return [[UIApplication sharedApplication] statusBarOrientation]; } - (instancetype)init { self = [super init]; if (self) { - _observers = [NSHashTable weakObjectsHashTable]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(statusBarOrientationChanged) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; + __weak HippyDeviceBaseInfo *devInfo = self; + NSString *notificationName; + if ([_bridge.delegate respondsToSelector:@selector(shouldUseViewWillTransitionMethodToMonitorOrientation)] + && _bridge.delegate.shouldUseViewWillTransitionMethodToMonitorOrientation) { + notificationName = HippyDimensionsShouldUpdateNotification; + } else { + notificationName = UIApplicationDidChangeStatusBarOrientationNotification; + } + _statusBarOrientationNotificationObserver = [[NSNotificationCenter defaultCenter] + addObserverForName:notificationName + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *_Nonnull note) { + if (devInfo) { + HippyDeviceBaseInfo *strongSelf = devInfo; + UIInterfaceOrientation previousInterfaceOrientation = strongSelf->_currentInterfaceOrientation; + UIInterfaceOrientation currentInterfaceOrientation = getStatusBarOrientation(); + if (previousInterfaceOrientation != currentInterfaceOrientation) { + NSDictionary *dim = hippyExportedDimensions(strongSelf->_bridge); + [strongSelf->_bridge.eventDispatcher dispatchEvent:@"Dimensions" methodName:@"set" args:dim]; + } + strongSelf->_currentInterfaceOrientation = currentInterfaceOrientation; + } + }]; + + _applicationDidBecomeActiveNotificationObserver = [[NSNotificationCenter defaultCenter] + addObserverForName:UIApplicationDidBecomeActiveNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *_Nonnull note) { + if (devInfo) { + HippyDeviceBaseInfo *strongSelf = devInfo; + UIInterfaceOrientation currentInterfaceOrientation = strongSelf->_currentInterfaceOrientation; + UIInterfaceOrientation activeStatusBarOrientation = getStatusBarOrientation(); + if (currentInterfaceOrientation != activeStatusBarOrientation) { + NSDictionary *dim = hippyExportedDimensions(strongSelf->_bridge); + [strongSelf->_bridge.eventDispatcher dispatchEvent:@"Dimensions" methodName:@"set" args:dim]; + } + strongSelf->_currentInterfaceOrientation = activeStatusBarOrientation; + } + }]; } return self; } - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - -- (void)addObserver:(id)observer { - [_observers addObject:observer]; -} - -- (void)removeObserver:(id)observer { - [_observers removeObject:observer]; -} - -- (void)statusBarOrientationChanged { - DisposeDimesions(); - for (id observer in _observers) { - [observer statusBarOrientationChanged]; - } -} - -@end - -@interface HippyDeviceBaseInfo () { + [[NSNotificationCenter defaultCenter] removeObserver:_statusBarOrientationNotificationObserver]; + [[NSNotificationCenter defaultCenter] removeObserver:_applicationDidBecomeActiveNotificationObserver]; } -@end - -@implementation HippyDeviceBaseInfo -HIPPY_EXPORT_MODULE(DeviceBaseInfo) - -@synthesize bridge = _bridge; +#pragma mark - Uitls -- (instancetype)init { - self = [super init]; - if (self) { - [[HippyBaseInfoInternal sharedInstance] addObserver:self]; ++ (BOOL)isUIScreenInOSDarkMode { + if (@available(iOS 12.0, *)) { + return (UIUserInterfaceStyleDark == [UIScreen mainScreen].traitCollection.userInterfaceStyle); + } else { + return NO; } - return self; } -- (void)statusBarOrientationChanged { - NSDictionary *dim = HippyExportedDimensions(); - [[self bridge].eventDispatcher dispatchEvent:@"Dimensions" methodName:@"set" args:dim]; -} @end diff --git a/framework/ios/base/bridge/HippyBridge.h b/framework/ios/base/bridge/HippyBridge.h index 0185d542438..a8f5e580259 100644 --- a/framework/ios/base/bridge/HippyBridge.h +++ b/framework/ios/base/bridge/HippyBridge.h @@ -253,11 +253,6 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass); */ - (void)setRedBoxShowEnabled:(BOOL)enabled; -/** - * just for debugger - */ -- (void)bindKeys; - /** * Use this to check if the bridge has been invalidated. */ @@ -312,6 +307,17 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass); - (void)resetRootSize:(CGSize)size; +#pragma mark - App UI State Related + +/// NightMode or not, default is NO. +/// Updated by HippyRootView +@property (atomic, assign, readonly) BOOL isOSNightMode; + +/// update `NightMode` state when changed +/// - Parameter isOSNightMode: bool +/// - Parameter rootViewTag: rootView's hippyTag +- (void)setOSNightMode:(BOOL)isOSNightMode withRootViewTag:(NSNumber *)rootViewTag; + @end diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index acf33e2e3e1..e40759488a2 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -81,6 +81,17 @@ NSString *const HippyDidInitializeModuleNotification = @"HippyDidInitializeModuleNotification"; NSString *const HippySDKVersion = @"unspecified"; + +static NSString *const HippyNativeGlobalKeyOS = @"OS"; +static NSString *const HippyNativeGlobalKeyOSVersion = @"OSVersion"; +static NSString *const HippyNativeGlobalKeyDevice = @"Device"; +static NSString *const HippyNativeGlobalKeySDKVersion = @"SDKVersion"; +static NSString *const HippyNativeGlobalKeyAppVersion = @"AppVersion"; +static NSString *const HippyNativeGlobalKeyDimensions = @"Dimensions"; +static NSString *const HippyNativeGlobalKeyLocalization = @"Localization"; +static NSString *const HippyNativeGlobalKeyNightMode = @"NightMode"; + + typedef NS_ENUM(NSUInteger, HippyBridgeFields) { HippyBridgeFieldRequestModuleIDs = 0, HippyBridgeFieldMethodIDs, @@ -106,6 +117,8 @@ @interface HippyBridge() { std::shared_ptr _uriLoader; std::shared_ptr _rootNode; + // 缓存的设备信息 + NSDictionary *_cachedDeviceInfo; } /// 用于标记bridge所使用的JS引擎的Key @@ -120,6 +133,10 @@ @interface HippyBridge() { @property(readwrite, strong) dispatch_semaphore_t moduleSemaphore; @property(readwrite, assign) NSInteger loadingCount; + +/// 缓存的Dimensions信息,用于传递给JS Side +@property (atomic, strong) NSDictionary *cachedDimensionsInfo; + @end @implementation HippyBridge @@ -176,12 +193,12 @@ - (instancetype)initWithDelegate:(id)delegate _startTime = footstone::TimePoint::SystemNow(); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rootViewContentDidAppear:) name:HippyContentDidAppearNotification object:nil]; - [self setUp]; HippyExecuteOnMainThread(^{ - [self bindKeys]; + self->_isOSNightMode = [HippyDeviceBaseInfo isUIScreenInOSDarkMode]; + self.cachedDimensionsInfo = hippyExportedDimensions(self); }, YES); - + [self setUp]; [self addImageProviderClass:[HippyDefaultImageProvider class]]; [self setVFSUriLoader:[self createURILoaderIfNeeded]]; @@ -232,19 +249,6 @@ - (void)dealloc { } } -- (void)bindKeys { -#if TARGET_IPHONE_SIMULATOR - HippyAssertMainQueue(); - HippyKeyCommands *commands = [HippyKeyCommands sharedInstance]; - - // reload in current mode - __weak __typeof(self) weakSelf = self; - [commands registerKeyCommandWithInput:@"r" modifierFlags:UIKeyModifierCommand action:^(__unused UIKeyCommand *command) { - [weakSelf requestReload]; - }]; -#endif -} - - (void)setUpNativeRenderManager { auto engineResource = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.engineKey]; auto domManager = engineResource->GetDomManager(); @@ -971,26 +975,76 @@ - (void)actuallyInvokeCallback:(NSNumber *)cbID arguments:(NSArray *)args { }]; } -- (NSDictionary *)deviceInfo { - //该方法可能从非UI线程调用 + +#pragma mark - DeviceInfo + +- (NSDictionary *)genRawDeviceInfoDict { + // This method may be called from a child thread NSString *iosVersion = [[UIDevice currentDevice] systemVersion]; struct utsname systemInfo; uname(&systemInfo); NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; NSMutableDictionary *deviceInfo = [NSMutableDictionary dictionary]; - [deviceInfo setValue:@"ios" forKey:@"OS"]; - [deviceInfo setValue:iosVersion forKey:@"OSVersion"]; - [deviceInfo setValue:deviceModel forKey:@"Device"]; - [deviceInfo setValue:HippySDKVersion forKey:@"SDKVersion"]; - [deviceInfo setValue:HippyExportedDimensions() forKey:@"Dimensions"]; + [deviceInfo setValue:@"ios" forKey:HippyNativeGlobalKeyOS]; + [deviceInfo setValue:iosVersion forKey:HippyNativeGlobalKeyOSVersion]; + [deviceInfo setValue:deviceModel forKey:HippyNativeGlobalKeyDevice]; + [deviceInfo setValue:HippySDKVersion forKey:HippyNativeGlobalKeySDKVersion]; + + NSString *appVer = [[NSBundle.mainBundle infoDictionary] objectForKey:@"CFBundleShortVersionString"]; + if (appVer) { + [deviceInfo setValue:appVer forKey:HippyNativeGlobalKeyAppVersion]; + } + + if (self.cachedDimensionsInfo) { + [deviceInfo setValue:self.cachedDimensionsInfo forKey:HippyNativeGlobalKeyDimensions]; + } + NSString *countryCode = [[HippyI18nUtils sharedInstance] currentCountryCode]; NSString *lanCode = [[HippyI18nUtils sharedInstance] currentAppLanguageCode]; NSWritingDirection direction = [[HippyI18nUtils sharedInstance] writingDirectionForCurrentAppLanguage]; - NSDictionary *local = @{@"country": countryCode?:@"unknown", @"language": lanCode?:@"unknown", @"direction": @(direction)}; - [deviceInfo setValue:local forKey:@"Localization"]; - return [NSDictionary dictionaryWithDictionary:deviceInfo]; + NSDictionary *localizaitionInfo = @{ + @"country" : countryCode?:@"unknown", + @"language" : lanCode?:@"unknown", + @"direction" : @(direction) + }; + [deviceInfo setValue:localizaitionInfo forKey:HippyNativeGlobalKeyLocalization]; + [deviceInfo setValue:@([self isOSNightMode]) forKey:HippyNativeGlobalKeyNightMode]; + return deviceInfo; +} + +- (NSDictionary *)deviceInfo { + @synchronized (self) { + if (!_cachedDeviceInfo) { + _cachedDeviceInfo = [self genRawDeviceInfoDict]; + } + return _cachedDeviceInfo; + } +} + + +#pragma mark - + +static NSString *const hippyOnNightModeChangedEvent = @"onNightModeChanged"; +static NSString *const hippyOnNightModeChangedParam1 = @"NightMode"; +static NSString *const hippyOnNightModeChangedParam2 = @"RootViewTag"; + +- (void)setOSNightMode:(BOOL)isOSNightMode withRootViewTag:(nonnull NSNumber *)rootViewTag { + _isOSNightMode = isOSNightMode; + // Notify to JS Driver Side + // 1. Update global object + [self.javaScriptExecutor updateNativeInfoToHippyGlobalObject:@{ HippyNativeGlobalKeyNightMode: @(isOSNightMode) }]; + + // 2. Send event + NSDictionary *args = @{@"eventName": hippyOnNightModeChangedEvent, + @"extra": @{ hippyOnNightModeChangedParam1 : @(isOSNightMode), + hippyOnNightModeChangedParam2 : rootViewTag } }; + [self.eventDispatcher dispatchEvent:@"EventDispatcher" + methodName:@"receiveNativeEvent" args:args]; } + +#pragma mark - + - (NSString *)moduleConfig { NSMutableArray *config = [NSMutableArray new]; for (HippyModuleData *moduleData in [_moduleSetup moduleDataByID]) { diff --git a/framework/ios/base/bridge/HippyBridgeDelegate.h b/framework/ios/base/bridge/HippyBridgeDelegate.h index c008d354702..2453facd476 100644 --- a/framework/ios/base/bridge/HippyBridgeDelegate.h +++ b/framework/ios/base/bridge/HippyBridgeDelegate.h @@ -79,4 +79,25 @@ */ - (void)invalidateForReason:(HippyInvalidateReason)reason bridge:(HippyBridge *)bridge; + +#pragma mark - UI/Layout Related + +/// When return YES, +/// it indicates that you want to use the `viewWillTransitionToSize` method in UIViewController +/// instead of the deprecated UIApplicationDidChangeStatusBarOrientationNotification. +/// +/// Note that you must call `onHostControllerTransitionedToSize` of HippyRootView when size changed. +- (BOOL)shouldUseViewWillTransitionMethodToMonitorOrientation; + +/// The default status bar height when hippy cannot obtained dynamically. +/// +/// Note: In general, the page layout should not depend on `StatusBar` height, +/// Its height is dynamically changed and should be obtained dynamically. +/// This value is only used as a default value if hippy cannot be obtained. +/// +/// Only for compatibility with old code, strongly discouraged. +/// return values less than 0 will be treated as 0. +- (CGFloat)defaultStatusBarHeightNoMatterHiddenOrNot; + + @end diff --git a/framework/ios/base/executors/HippyJSExecutor.h b/framework/ios/base/executors/HippyJSExecutor.h index d6fbcfb7851..98c730c74f4 100644 --- a/framework/ios/base/executors/HippyJSExecutor.h +++ b/framework/ios/base/executors/HippyJSExecutor.h @@ -140,4 +140,8 @@ HIPPY_EXTERN NSString *const HippyJSCThreadName; */ - (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block; +/// Updated hippy global info +/// - Parameter dict: updated info +- (void)updateNativeInfoToHippyGlobalObject:(NSDictionary *)dict; + @end diff --git a/framework/ios/base/executors/HippyJSExecutor.mm b/framework/ios/base/executors/HippyJSExecutor.mm index 4341f671f3e..2dd25e4e8db 100644 --- a/framework/ios/base/executors/HippyJSExecutor.mm +++ b/framework/ios/base/executors/HippyJSExecutor.mm @@ -409,6 +409,20 @@ - (void)dealloc { [self invalidate]; } +- (void)updateNativeInfoToHippyGlobalObject:(NSDictionary *)updatedInfoDict { + if (updatedInfoDict.count <= 0){ + return; + } + __weak __typeof(self)weakSelf = self; + [self executeBlockOnJavaScriptQueue:^{ + __strong __typeof(weakSelf)strongSelf = weakSelf; + if (!strongSelf || !strongSelf.isValid || nullptr == strongSelf.pScope) { + return; + } + [strongSelf addInfoToGlobalObject:updatedInfoDict.copy]; + }]; +} + -(void)addInfoToGlobalObject:(NSDictionary*)addInfoDict{ string_view str("__HIPPYNATIVEGLOBAL__"); auto context = self.pScope->GetContext(); diff --git a/renderer/native/ios/renderer/HippyComponentData.h b/renderer/native/ios/renderer/HippyComponentData.h index fd9bee564d5..56d541af26c 100644 --- a/renderer/native/ios/renderer/HippyComponentData.h +++ b/renderer/native/ios/renderer/HippyComponentData.h @@ -47,6 +47,6 @@ - (NSDictionary *)methodsByName; -- (HippyViewManagerUIBlock)uiBlockToAmendWithRenderObjectViewRegistry:(NSDictionary *)registry; +- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary *)registry; @end diff --git a/renderer/native/ios/renderer/HippyComponentData.mm b/renderer/native/ios/renderer/HippyComponentData.mm index 7efbeb6bb44..518171f627c 100644 --- a/renderer/native/ios/renderer/HippyComponentData.mm +++ b/renderer/native/ios/renderer/HippyComponentData.mm @@ -509,7 +509,7 @@ - (NSString *)selectorStringFromSignature:(NSString *)signature { return [selString copy]; } -- (HippyViewManagerUIBlock)uiBlockToAmendWithRenderObjectViewRegistry:(NSDictionary *)registry { +- (HippyViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary *)registry { if (_implementsUIBlockToAmendWithRenderObjectRegistry) { return [[self manager] uiBlockToAmendWithShadowViewRegistry:registry]; } diff --git a/renderer/native/ios/renderer/HippyRootView.h b/renderer/native/ios/renderer/HippyRootView.h index 15d12b21591..f9d5cf55fdf 100644 --- a/renderer/native/ios/renderer/HippyRootView.h +++ b/renderer/native/ios/renderer/HippyRootView.h @@ -25,40 +25,22 @@ @class HippyBridge; -#pragma mark - -/** - * This enum is used to define size flexibility type of the root view. - * If a dimension is flexible, the view will recalculate that dimension - * so the content fits. Recalculations are performed when the root's frame, - * size flexibility mode or content size changes. After a recalculation, - * rootViewDidChangeIntrinsicSize method of the HippyRootViewDelegate will be called. - */ -typedef NS_ENUM(NSInteger, HippyRootViewSizeFlexibility) { - HippyRootViewSizeFlexibilityNone = 0, - HippyRootViewSizeFlexibilityWidth, - HippyRootViewSizeFlexibilityHeight, - HippyRootViewSizeFlexibilityWidthAndHeight, -}; - -/** - * This notification is sent when the first subviews are added to the root view - * after the application has loaded. This is used to hide the `loadingView`, and - * is a good indicator that the application is ready to use. - */ +/// This notification is sent when the first subviews are added to the root view +/// after the application has loaded. This is used to hide the `loadingView`, and +/// is a good indicator that the application is ready to use. extern NSString *const HippyContentDidAppearNotification; - - +/// Business bundle loading completion notification +/// This notification is for compatibility with hippy2 and is not recommended for further use extern NSString *const HippySecondaryBundleDidLoadNotification DEPRECATED_MSG_ATTRIBUTE("Use HippyRootView's delegate"); -/** - * Native view used to host Hippy-managed views within the app. Can be used just - * like any ordinary UIView. You can have multiple HippyRootViews on screen at - * once, all controlled by the same JavaScript application. - */ +/// Native view used to host Hippy-managed views within the app. +/// Can be used just like any ordinary UIView. +/// You can have multiple HippyRootViews on screen at once, +/// all controlled by the same JavaScript application. @interface HippyRootView : UIView /// Create HippyRootView instance @@ -67,7 +49,6 @@ extern NSString *const HippySecondaryBundleDidLoadNotification DEPRECATED_MSG_AT /// @param moduleName module name /// @param initialProperties application properties, see appProperties property. /// @param delegate HippyRootViewDelegate -/// - (instancetype)initWithBridge:(HippyBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties @@ -88,70 +69,35 @@ extern NSString *const HippySecondaryBundleDidLoadNotification DEPRECATED_MSG_AT initialProperties:(NSDictionary *)initialProperties delegate:(id)delegate; +/// The delegate of hippyRootView. +@property (nonatomic, weak) id delegate; -/** - * The name of the JavaScript module to execute within the - * specified scriptURL (required). Setting this will not have - * any immediate effect, but it must be done prior to loading - * the script. - */ +/// The name of the JavaScript module to execute within the +/// specified scriptURL (required). Setting this will not have +/// any immediate effect, but it must be done prior to loading the script. @property (nonatomic, copy, readonly) NSString *moduleName; -/** - * The bridge used by the root view. Bridges can be shared between multiple - * root views, so you can use this property to initialize another HippyRootView. - */ +/// The bridge used by the root view. Bridges can be shared between multiple +/// root views, so you can use this property to initialize another HippyRootView. @property (nonatomic, strong, readonly) HippyBridge *bridge; -/** - * The properties to apply to the view. Use this property to update - * application properties and rerender the view. Initialized with - * initialProperties argument of the initializer. - * - * Set this property only on the main thread. - */ +/// The properties to apply to the view. Use this property to update +/// application properties and rerender the view. Initialized with +/// initialProperties argument of the initializer. +/// Set this property only on the main thread. @property (nonatomic, copy, readwrite) NSDictionary *appProperties; -/** - * The size flexibility mode of the root view. - */ -@property (nonatomic, assign) HippyRootViewSizeFlexibility sizeFlexibility; - -/** - * The size of the root view's content. This is set right before the - * rootViewDidChangeIntrinsicSize method of HippyRootViewDelegate is called. - */ -@property (readonly, nonatomic, assign) CGSize intrinsicSize; - -/** - * The delegate that handles intrinsic size updates. - */ -@property (nonatomic, weak) id delegate; - -/** - * The backing view controller of the root view. - */ +/// The backing view controller of the root view. @property (nonatomic, weak) UIViewController *hippyViewController; -/** - * The Hippy-managed contents view of the root view. - */ -@property (nonatomic, strong, readonly) UIView *contentView; - - -- (void)contentDidAppear; - -/** - * Timings for hiding the loading view after the content has loaded. Both of - * these values default to 0.25 seconds. - */ -@property (nonatomic, assign) NSTimeInterval loadingViewFadeDelay; -@property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration; - - +/// Run Hippy +/// +/// This is the Hippy program entry. +/// - (void)runHippyApplication; + #pragma mark - /// This method should be called when the host controller's view's size is changed diff --git a/renderer/native/ios/renderer/HippyRootView.mm b/renderer/native/ios/renderer/HippyRootView.mm index 7d71a8e59aa..d0d044e092a 100644 --- a/renderer/native/ios/renderer/HippyRootView.mm +++ b/renderer/native/ios/renderer/HippyRootView.mm @@ -27,6 +27,7 @@ #import "NativeRenderDefines.h" #import "HippyInvalidating.h" #import "HippyBridge.h" +#import "HippyDeviceBaseInfo.h" #include NSString *const HippyContentDidAppearNotification = @"HippyContentDidAppearNotification"; @@ -41,31 +42,11 @@ } -@interface HippyRootContentView : HippyView - -@property (nonatomic, readonly) BOOL contentHasAppeared; -//@property (nonatomic, strong) HippyTouchHandler *touchHandler; -@property (nonatomic, assign) int64_t startTimpStamp; - -- (instancetype)initWithFrame:(CGRect)frame - bridge:(HippyBridge *)bridge - hippyTag:(NSNumber *)hippyTag - sizeFlexiblity:(HippyRootViewSizeFlexibility)sizeFlexibility NS_DESIGNATED_INITIALIZER; - -@end - - @interface HippyRootView () { BOOL _contentHasAppeared; - HippyRootContentView *_contentView; } -/** - * The Hippy-managed contents view of the root view. - */ -@property (nonatomic, strong) UIView *contentView; - @property (nonatomic, strong) NSDictionary *shareOptions; @end @@ -93,7 +74,6 @@ - (instancetype)initWithBridge:(HippyBridge *)bridge } _moduleName = moduleName; _appProperties = [initialProperties copy]; - _sizeFlexibility = HippyRootViewSizeFlexibilityNone; _delegate = delegate; self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; @@ -154,7 +134,6 @@ - (instancetype)initWithBridge:(HippyBridge *)bridge } - (void)dealloc { - [_contentView invalidate]; if ([_delegate respondsToSelector:@selector(rootViewWillBePurged:)]) { [_delegate rootViewWillBePurged:self]; } @@ -167,26 +146,15 @@ - (void)runHippyApplication { __weak __typeof(self)weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ __strong __typeof(weakSelf)strongSelf = weakSelf; - [strongSelf.contentView removeFromSuperview]; - strongSelf.contentView = [[HippyRootContentView alloc] initWithFrame:strongSelf.bounds - bridge:strongSelf.bridge - hippyTag:strongSelf.hippyTag - sizeFlexiblity:strongSelf.sizeFlexibility]; - // 注册 + // 注册RootView [strongSelf.bridge setRootView:strongSelf]; [strongSelf.bridge loadInstanceForRootView:strongSelf.hippyTag withProperties:strongSelf.appProperties]; HippyLogInfo(@"[Hippy_OC_Log][Life_Circle],Running application %@ (%@)", strongSelf.moduleName, strongSelf.appProperties); }); } - -- (void)setBackgroundColor:(UIColor *)backgroundColor { - super.backgroundColor = backgroundColor; - _contentView.backgroundColor = backgroundColor; -} - - (UIViewController *)hippyViewController { - return _hippyViewController?:[super hippyViewController]; + return _hippyViewController ?: [super hippyViewController]; } - (BOOL)canBecomeFirstResponder { @@ -244,16 +212,6 @@ - (void)insertHippySubview:(UIView *)subview atIndex:(NSInteger)atIndex { }); } -- (void)setSizeFlexibility:(HippyRootViewSizeFlexibility)sizeFlexibility { - _sizeFlexibility = sizeFlexibility; - [self setNeedsLayout]; -} - -- (void)layoutSubviews { - [super layoutSubviews]; - _contentView.frame = self.bounds; -} - - (void)setAppProperties:(NSDictionary *)appProperties { HippyAssertMainQueue(); @@ -263,129 +221,33 @@ - (void)setAppProperties:(NSDictionary *)appProperties { _appProperties = [appProperties copy]; - if (_contentView && _bridge.valid && !_bridge.loading) { + if (_bridge.valid) { [self runHippyApplication]; } } -- (void)setIntrinsicSize:(CGSize)intrinsicSize { - BOOL oldSizeHasAZeroDimension = _intrinsicSize.height == 0 || _intrinsicSize.width == 0; - BOOL newSizeHasAZeroDimension = intrinsicSize.height == 0 || intrinsicSize.width == 0; - BOOL bothSizesHaveAZeroDimension = oldSizeHasAZeroDimension && newSizeHasAZeroDimension; - - BOOL sizesAreEqual = CGSizeEqualToSize(_intrinsicSize, intrinsicSize); - - _intrinsicSize = intrinsicSize; - - // Don't notify the delegate if the content remains invisible or its size has not changed - if (bothSizesHaveAZeroDimension || sizesAreEqual) { - return; - } - if ([_delegate respondsToSelector:@selector(rootViewDidChangeIntrinsicSize:)]) { - [_delegate rootViewDidChangeIntrinsicSize:self]; - } -} - -- (void)contentViewInvalidated { - [_contentView removeFromSuperview]; - _contentView = nil; -} - #pragma mark - -//- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { -// [super traitCollectionDidChange:previousTraitCollection]; -// if (@available(iOS 12.0, *)) { -// // on dark mode change -// UIUserInterfaceStyle currentStyle = self.traitCollection.userInterfaceStyle; -// if (currentStyle != previousTraitCollection.userInterfaceStyle) { -// BOOL isNightMode = (UIUserInterfaceStyleDark == currentStyle); -// if (self.bridge.isOSNightMode != isNightMode) { -// [self.bridge setOSNightMode:isNightMode withRootViewTag:self.hippyTag]; -// } -// } -// } -//} -// -//static NSString *const HippyHostControllerSizeKeyNewSize = @"NewSize"; -//- (void)onHostControllerTransitionedToSize:(CGSize)size { -// [NSNotificationCenter.defaultCenter postNotificationName:HippyDimensionsShouldUpdateNotification -// object:nil -// userInfo:@{HippyHostControllerSizeKeyNewSize : @(size)}]; -//} - -@end - - -@implementation HippyRootContentView { - __weak HippyBridge *_bridge; - UIColor *_backgroundColor; -} - -- (instancetype)initWithFrame:(CGRect)frame - bridge:(HippyBridge *)bridge - hippyTag:(NSNumber *)hippyTag - sizeFlexiblity:(HippyRootViewSizeFlexibility)sizeFlexibility { - if ((self = [super initWithFrame:frame])) { - _bridge = bridge; - self.hippyTag = hippyTag; - -// _touchHandler = [[HippyTouchHandler alloc] initWithRootView:self bridge:bridge]; -// [self addGestureRecognizer:_touchHandler]; -// [_bridge.uiManager registerRootView:self withSizeFlexibility:sizeFlexibility]; - - self.layer.backgroundColor = NULL; - _startTimpStamp = CACurrentMediaTime() * 1000; - } - return self; -} - -HIPPY_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame) -HIPPY_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (nonnull NSCoder *)aDecoder) - -- (void)insertHippySubview:(UIView *)subview atIndex:(NSInteger)atIndex { - [super insertHippySubview:subview atIndex:atIndex]; -// [_bridge.performanceLogger markStopForTag:HippyPLTTI]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if (!self->_contentHasAppeared) { - self->_contentHasAppeared = YES; -// int64_t cost = [self->_bridge.performanceLogger durationForTag:HippyPLTTI]; -// [[NSNotificationCenter defaultCenter] postNotificationName:HippyContentDidAppearNotification object:self.superview userInfo:@{ -// @"cost": @(cost) -// }]; - } - }); -} - -- (void)setFrame:(CGRect)frame { - CGRect originFrame = self.frame; - if (!CGRectEqualToRect(originFrame, frame)) { - super.frame = frame; - if (self.hippyTag && _bridge.isValid) { -// [_bridge.uiManager setFrame:frame fromOriginFrame:originFrame forView:self]; +- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { + [super traitCollectionDidChange:previousTraitCollection]; + if (@available(iOS 12.0, *)) { + // on dark mode change + UIUserInterfaceStyle currentStyle = self.traitCollection.userInterfaceStyle; + if (currentStyle != previousTraitCollection.userInterfaceStyle) { + BOOL isNightMode = (UIUserInterfaceStyleDark == currentStyle); + if (self.bridge.isOSNightMode != isNightMode) { + [self.bridge setOSNightMode:isNightMode withRootViewTag:self.hippyTag]; + } } } } -- (void)setBackgroundColor:(UIColor *)backgroundColor { - _backgroundColor = backgroundColor; - if (self.hippyTag && _bridge.isValid) { -// [_bridge.uiManager setBackgroundColor:backgroundColor forView:self]; - } -} - -- (UIColor *)backgroundColor { - return _backgroundColor; -} - -- (void)invalidate { - if (self.userInteractionEnabled) { - self.userInteractionEnabled = NO; - [(HippyRootView *)self.superview contentViewInvalidated]; - [_bridge enqueueJSCall:@"AppRegistry" method:@"unmountApplicationComponentAtRootTag" args:@[self.hippyTag] completion:NULL]; - } +static NSString *const HippyHostControllerSizeKeyNewSize = @"NewSize"; +- (void)onHostControllerTransitionedToSize:(CGSize)size { + [NSNotificationCenter.defaultCenter postNotificationName:HippyDimensionsShouldUpdateNotification + object:self + userInfo:@{HippyHostControllerSizeKeyNewSize : @(size)}]; } @end diff --git a/renderer/native/ios/renderer/HippyRootViewDelegate.h b/renderer/native/ios/renderer/HippyRootViewDelegate.h index f9716866720..7dad3386221 100644 --- a/renderer/native/ios/renderer/HippyRootViewDelegate.h +++ b/renderer/native/ios/renderer/HippyRootViewDelegate.h @@ -27,15 +27,6 @@ @protocol HippyRootViewDelegate @optional -/** - * Called after the root view's content is updated to a new size. The method is not called - * when both old size and new size have a dimension that equals to zero. - * - * The delegate can use this callback to appropriately resize the root view frame to fit the new - * content view size. The view will not resize itself. The new content size is available via the - * intrinsicSize propery of the root view. - */ -- (void)rootViewDidChangeIntrinsicSize:(HippyRootView *)rootView; /** * Called after finish load the bundle. diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 178e6788fec..4d4a6eef232 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -164,8 +164,8 @@ static void NativeRenderTraverseViewNodes(id view, void (^block) @interface HippyUIManager() { NSMutableArray *_pendingUIBlocks; - HippyComponentMap *_renderObjectRegistry; HippyComponentMap *_viewRegistry; + HippyComponentMap *_shadowViewRegistry; // Keyed by viewName NSMutableDictionary *_componentDataByName; @@ -207,7 +207,7 @@ - (void)dealloc { } - (void)initContext { - _renderObjectRegistry = [[HippyComponentMap alloc] init]; + _shadowViewRegistry = [[HippyComponentMap alloc] init]; _viewRegistry = [[HippyComponentMap alloc] init]; _viewRegistry.requireInMainThread = YES; _pendingUIBlocks = [NSMutableArray new]; @@ -258,10 +258,10 @@ - (void)domNodeForComponentTag:(int32_t)componentTag } - (HippyComponentMap *)renderObjectRegistry { - if (!_renderObjectRegistry) { - _renderObjectRegistry = [[HippyComponentMap alloc] init]; + if (!_shadowViewRegistry) { + _shadowViewRegistry = [[HippyComponentMap alloc] init]; } - return _renderObjectRegistry; + return _shadowViewRegistry; } - (HippyComponentMap *)viewRegistry { @@ -284,7 +284,7 @@ - (UIView *)viewForComponentTag:(NSNumber *)componentTag - (HippyShadowView *)renderObjectForcomponentTag:(NSNumber *)componentTag onRootTag:(NSNumber *)rootTag { - return [_renderObjectRegistry componentForTag:componentTag onRootTag:rootTag]; + return [_shadowViewRegistry componentForTag:componentTag onRootTag:rootTag]; } - (std::weak_ptr)renderManager { @@ -347,7 +347,7 @@ - (void)registerRootView:(UIView *)rootView asRootNode:(std::weak_ptr) renderObject.viewName = rootViewClassName; renderObject.rootNode = rootNode; renderObject.domNode = rootNode; - [strongSelf->_renderObjectRegistry addRootComponent:renderObject rootNode:rootNode forTag:componentTag]; + [strongSelf->_shadowViewRegistry addRootComponent:renderObject rootNode:rootNode forTag:componentTag]; NSDictionary *userInfo = @{ NativeRenderUIManagerRootViewTagKey: componentTag, NativeRenderUIManagerKey: strongSelf}; [[NSNotificationCenter defaultCenter] postNotificationName:NativeRenderUIManagerDidRegisterRootViewNotification @@ -366,7 +366,7 @@ - (void)unregisterRootViewFromTag:(NSNumber *)rootTag { } std::lock_guard lock([self renderQueueLock]); [_viewRegistry removeRootComponentWithTag:rootTag]; - [_renderObjectRegistry removeRootComponentWithTag:rootTag]; + [_shadowViewRegistry removeRootComponentWithTag:rootTag]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { @@ -415,13 +415,13 @@ - (void)setFrame:(CGRect)frame forRootView:(UIView *)view { return; } HippyUIManager *strongSelf = weakSelf; - HippyShadowView *renderObject = [strongSelf->_renderObjectRegistry rootComponentForTag:componentTag]; + HippyShadowView *renderObject = [strongSelf->_shadowViewRegistry rootComponentForTag:componentTag]; if (renderObject == nil) { return; } if (!CGRectEqualToRect(frame, renderObject.frame)) { renderObject.frame = frame; - std::weak_ptr rootNode = [strongSelf->_renderObjectRegistry rootNodeForTag:componentTag]; + std::weak_ptr rootNode = [strongSelf->_shadowViewRegistry rootNodeForTag:componentTag]; [strongSelf batchOnRootNode:rootNode]; } }}; @@ -464,7 +464,7 @@ - (void)removeChildren:(NSArray> *)children fromContainer:(id - (UIView *)createViewRecursivelyFromcomponentTag:(NSNumber *)componentTag onRootTag:(NSNumber *)rootTag { - HippyShadowView *renderObject = [_renderObjectRegistry componentForTag:componentTag onRootTag:rootTag]; + HippyShadowView *renderObject = [_shadowViewRegistry componentForTag:componentTag onRootTag:rootTag]; return [self createViewRecursivelyFromRenderObject:renderObject]; } @@ -548,7 +548,7 @@ - (NSDictionary *)createRenderObjectFromNode:(const std::shared_ptrGetLayoutResult(); renderObject.frame = CGRectMakeFromLayoutResult(domNode->GetLayoutResult()); [componentData setProps:props forShadowView:renderObject]; - [_renderObjectRegistry addComponent:renderObject forRootTag:rootTag]; + [_shadowViewRegistry addComponent:renderObject forRootTag:rootTag]; } return props; } @@ -591,7 +591,7 @@ - (UIView *)createViewByComponentData:(HippyComponentData *)componentData - (void)updateView:(nonnull NSNumber *)componentTag onRootTag:(NSNumber *)rootTag props:(NSDictionary *)props { - HippyShadowView *renderObject = [_renderObjectRegistry componentForTag:componentTag onRootTag:rootTag]; + HippyShadowView *renderObject = [_shadowViewRegistry componentForTag:componentTag onRootTag:rootTag]; if (!renderObject) { return; } @@ -738,16 +738,16 @@ - (void)createRenderNodes:(std::vector> &&)nodes } [manager enumerateViewsHierarchy:^(int32_t tag, const std::vector &subviewTags, const std::vector &subviewIndices) { NSAssert(subviewTags.size() == subviewIndices.size(), @"subviewTags count must be equal to subviewIndices count"); - HippyShadowView *superRenderObject = [self->_renderObjectRegistry componentForTag:@(tag) onRootTag:rootNodeTag]; + HippyShadowView *superRenderObject = [self->_shadowViewRegistry componentForTag:@(tag) onRootTag:rootNodeTag]; for (NSUInteger index = 0; index < subviewTags.size(); index++) { - HippyShadowView *subRenderObject = [self->_renderObjectRegistry componentForTag:@(subviewTags[index]) onRootTag:rootNodeTag]; + HippyShadowView *subRenderObject = [self->_shadowViewRegistry componentForTag:@(subviewTags[index]) onRootTag:rootNodeTag]; [superRenderObject insertHippySubview:subRenderObject atIndex:subviewIndices[index]]; } [superRenderObject didUpdateHippySubviews]; }]; for (const std::shared_ptr &node : nodes) { NSNumber *componentTag = @(node->GetId()); - HippyShadowView *renderObject = [_renderObjectRegistry componentForTag:componentTag onRootTag:rootNodeTag]; + HippyShadowView *renderObject = [_shadowViewRegistry componentForTag:componentTag onRootTag:rootNodeTag]; if (NativeRenderCreationTypeInstantly == [renderObject creationType] && !_uiCreationLazilyEnabled) { [self addUIBlock:^(HippyUIManager *uiManager, __unused NSDictionary *viewRegistry) { UIView *view = [uiManager createViewFromRenderObject:renderObject]; @@ -759,7 +759,7 @@ - (void)createRenderNodes:(std::vector> &&)nodes [manager enumerateViewsHierarchy:^(int32_t tag, const std::vector &subviewTags, const std::vector &subviewIndices) { auto subViewTags_ = subviewTags; auto subViewIndices_ = subviewIndices; - HippyShadowView *renderObject = [self->_renderObjectRegistry componentForTag:@(tag) onRootTag:rootNodeTag]; + HippyShadowView *renderObject = [self->_shadowViewRegistry componentForTag:@(tag) onRootTag:rootNodeTag]; if (NativeRenderCreationTypeInstantly == [renderObject creationType] && !self->_uiCreationLazilyEnabled) { [self addUIBlock:^(HippyUIManager *uiManager, NSDictionary *viewRegistry) { UIView *superView = viewRegistry[@(tag)]; @@ -822,7 +822,7 @@ - (void)deleteRenderNodesIds:(std::vector> &&)no #endif std::lock_guard lock([self renderQueueLock]); NSNumber *rootTag = @(strongRootNode->GetId()); - NSMutableDictionary *currentRegistry = [_renderObjectRegistry componentsForRootTag:rootTag]; + NSMutableDictionary *currentRegistry = [_shadowViewRegistry componentsForRootTag:rootTag]; for (auto dom_node : nodes) { int32_t tag = dom_node->GetRenderInfo().id; @@ -875,12 +875,12 @@ - (void)renderMoveViews:(const std::vector &&)ids } int32_t rootTag = strongRootNode->GetId(); - HippyShadowView *fromObjectView = [_renderObjectRegistry componentForTag:@(fromContainer) + HippyShadowView *fromObjectView = [_shadowViewRegistry componentForTag:@(fromContainer) onRootTag:@(rootTag)]; - HippyShadowView *toObjectView = [_renderObjectRegistry componentForTag:@(toContainer) + HippyShadowView *toObjectView = [_shadowViewRegistry componentForTag:@(toContainer) onRootTag:@(rootTag)]; for (int32_t componentTag : ids) { - HippyShadowView *view = [_renderObjectRegistry componentForTag:@(componentTag) onRootTag:@(rootTag)]; + HippyShadowView *view = [_shadowViewRegistry componentForTag:@(componentTag) onRootTag:@(rootTag)]; HippyAssert(fromObjectView == [view parentComponent], @"parent of object view with tag %d is not object view with tag %d", componentTag, fromContainer); [view removeFromHippySuperview]; [toObjectView insertHippySubview:view atIndex:index]; @@ -921,7 +921,7 @@ - (void)renderMoveNodes:(std::vector> &&)nodes for (auto &node : nodes) { int32_t index = node->GetRenderInfo().index; int32_t componentTag = node->GetId(); - HippyShadowView *objectView = [_renderObjectRegistry componentForTag:@(componentTag) onRootTag:@(rootTag)]; + HippyShadowView *objectView = [_shadowViewRegistry componentForTag:@(componentTag) onRootTag:@(rootTag)]; [objectView dirtyPropagation:NativeRenderUpdateLifecycleLayoutDirtied]; HippyAssert(!parentObjectView || parentObjectView == [objectView parentComponent], @"try to move object view on different parent object view"); if (!parentObjectView) { @@ -964,7 +964,7 @@ - (void)updateNodesLayout:(const std::vector(layoutInfoTuple); CGRect frame = CGRectMakeFromLayoutResult(layoutResult); - HippyShadowView *renderObject = [_renderObjectRegistry componentForTag:componentTag onRootTag:rootTag]; + HippyShadowView *renderObject = [_shadowViewRegistry componentForTag:componentTag onRootTag:rootTag]; if (renderObject) { [renderObject dirtyPropagation:NativeRenderUpdateLifecycleLayoutDirtied]; renderObject.frame = frame; @@ -1440,7 +1440,7 @@ - (void)layoutAndMountOnRootNode:(std::weak_ptr)rootNode { return; } int32_t root_id = strongRootNode->GetId(); - HippyShadowView *rootView = [_renderObjectRegistry rootComponentForTag:@(root_id)]; + HippyShadowView *rootView = [_shadowViewRegistry rootComponentForTag:@(root_id)]; NSMutableSet *uiBlocks = [NSMutableSet setWithCapacity:128]; [rootView amendLayoutBeforeMount:uiBlocks]; if (uiBlocks.count) { @@ -1462,7 +1462,7 @@ - (void)layoutAndMountOnRootNode:(std::weak_ptr)rootNode { - (void)setNeedsLayoutForRootNodeTag:(NSNumber *)tag { // If there is an active batch layout will happen when batch finished, so we will wait for that. // Otherwise we immidiately trigger layout. - auto rootNode = [_renderObjectRegistry rootNodeForTag:tag]; + auto rootNode = [_shadowViewRegistry rootNodeForTag:tag]; [self layoutAndMountOnRootNode:rootNode]; } diff --git a/renderer/native/ios/utils/NativeRenderUtils.h b/renderer/native/ios/utils/NativeRenderUtils.h index b941dcaa657..fc85ede6517 100644 --- a/renderer/native/ios/utils/NativeRenderUtils.h +++ b/renderer/native/ios/utils/NativeRenderUtils.h @@ -21,7 +21,6 @@ */ #import - #import "HippyDefines.h" NS_ASSUME_NONNULL_BEGIN