diff --git a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m index 45f9e2abeeb..a72feaec16d 100644 --- a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m +++ b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m @@ -23,13 +23,7 @@ #import "HippyDemoViewController.h" #import "UIViewController+Title.h" #import "HippyPageCache.h" - -#import -#import -#import -#import -#import -#import +@import hippy; @interface HippyDemoViewController () { diff --git a/framework/examples/ios-demo/HippyDemo/turbomodule/TurboConfig.m b/framework/examples/ios-demo/HippyDemo/turbomodule/TurboConfig.m index 088a7d96e81..5d621ffe6dc 100644 --- a/framework/examples/ios-demo/HippyDemo/turbomodule/TurboConfig.m +++ b/framework/examples/ios-demo/HippyDemo/turbomodule/TurboConfig.m @@ -22,7 +22,6 @@ #import "TurboConfig.h" #import "HippyDefines.h" -#import "HippyDefines.h" @interface TurboConfig () diff --git a/framework/examples/ios-demo/podfile b/framework/examples/ios-demo/podfile index 506f7b68ee6..132a71715c7 100644 --- a/framework/examples/ios-demo/podfile +++ b/framework/examples/ios-demo/podfile @@ -9,7 +9,10 @@ workspace 'HippyDemo.xcworkspace' target "HippyDemo" do platform :ios, '11.0' - pod 'hippy', :path => '../../..', :testspecs => ['UnitTests'] + # pod hippy, + # set modular_headers to true if you want to use modular import + # no need to set testspecs in your production app + pod 'hippy', :path => '../../..', :modular_headers => true, :testspecs => ['UnitTests'] end diff --git a/framework/ios/base/bridge/HippyBridge+PerformanceAPI.mm b/framework/ios/base/bridge/HippyBridge+PerformanceAPI.mm index e60b3adc90b..8f4b31925e2 100644 --- a/framework/ios/base/bridge/HippyBridge+PerformanceAPI.mm +++ b/framework/ios/base/bridge/HippyBridge+PerformanceAPI.mm @@ -21,7 +21,7 @@ */ #import "HippyBridge+PerformanceAPI.h" -#import "HippyJSExecutor.h" +#import "HippyJSExecutor+Internal.h" #import "HippyLog.h" #import "driver/scope.h" diff --git a/framework/ios/base/bridge/HippyBridge+Private.h b/framework/ios/base/bridge/HippyBridge+Private.h index 2d7e45ed910..2a333975c9c 100644 --- a/framework/ios/base/bridge/HippyBridge+Private.h +++ b/framework/ios/base/bridge/HippyBridge+Private.h @@ -24,7 +24,7 @@ #define HippyBridge_Private_h #import "HippyBridge.h" -#import "footstone/time_point.h" +#include "footstone/time_point.h" #include class VFSUriLoader; diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index df7dea8be9b..1de3a8eecb1 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -27,7 +27,7 @@ #import "HippyEventDispatcher.h" #import "HippyFileHandler.h" #import "HippyJSEnginesMapper.h" -#import "HippyJSExecutor.h" +#import "HippyJSExecutor+Internal.h" #import "HippyKeyCommands.h" #import "HippyModuleData.h" #import "HippyModuleMethod.h" @@ -589,7 +589,8 @@ - (void)beginLoadingBundle:(NSURL *)bundleURL if (!strongSelf || !strongSelf.valid || !script) { NSString *errMsg = [NSString stringWithFormat:@"Bundle Execution Operation Fail! valid:%d, script:%@", strongSelf.valid, script]; - completion(nil, HippyErrorWithMessage(errMsg)); + HippyLogError(@"%@", errMsg); + completion(bundleURL, HippyErrorWithMessage(errMsg)); strongSelf.lastExecuteOperation = nil; return; } @@ -1294,9 +1295,8 @@ - (void)setRootView:(UIView *)rootView { // But one HippyBridge can only have one UIManager. HippyUIManager *uiManager = self.uiManager; if (!uiManager) { - uiManager = [[HippyUIManager alloc] init]; + uiManager = [[HippyUIManager alloc] initWithBridge:self]; [uiManager setDomManager:domManager]; - [uiManager setBridge:self]; self.uiManager = uiManager; } diff --git a/framework/ios/base/executors/HippyJSExecutor+Internal.h b/framework/ios/base/executors/HippyJSExecutor+Internal.h new file mode 100644 index 00000000000..6980216d3e2 --- /dev/null +++ b/framework/ios/base/executors/HippyJSExecutor+Internal.h @@ -0,0 +1,62 @@ +/*! + * 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 HippyJSExecutor_Internal_h +#define HippyJSExecutor_Internal_h + +#import "HippyJSExecutor.h" +#include + +namespace hippy { +inline namespace driver { +inline namespace napi { +class CtxValue; +} +class Scope; +} +inline namespace vfs { +class UriLoader; +} +} + + +@protocol HippyJSExecutorInternal + +/// hippy scope +@property (atomic, readonly) std::shared_ptr pScope; + +/// Set Uri loader +/// - Parameter uriLoader: vfs::UriLoader +- (void)setUriLoader:(std::weak_ptr)uriLoader; + +/// Get turbo object +/// - Parameter name: NSString +- (std::shared_ptr)JSTurboObjectWithName:(NSString *)name; + +@end + +@interface HippyJSExecutor (Internal) + +@end + + +#endif /* HippyJSExecutor_Internal_h */ diff --git a/framework/ios/base/executors/HippyJSExecutor.h b/framework/ios/base/executors/HippyJSExecutor.h index 69d7ae174ae..64cc3ae47c9 100644 --- a/framework/ios/base/executors/HippyJSExecutor.h +++ b/framework/ios/base/executors/HippyJSExecutor.h @@ -24,36 +24,15 @@ #import "HippyDefines.h" #import "HippyDefines.h" #import "HippyInvalidating.h" -#include +@class HippyBridge; /** * Block that when js script execution completion */ typedef void (^HippyJavaScriptCallback)(id result, NSError *error); - - -namespace hippy { -inline namespace driver { - -inline namespace napi { -class CtxValue; -} - -class Scope; - -} - -inline namespace vfs { -class UriLoader; -} - -} - -@class HippyBridge; typedef void (^HippyContextCreatedBlock)(void); - /** * Uses a JavaScriptCore context as the execution engine. */ @@ -68,9 +47,6 @@ typedef void (^HippyContextCreatedBlock)(void); /// EngineKey @property (nonatomic, copy) NSString *enginekey; -/// hippy scope -@property (atomic, assign) std::shared_ptr pScope; - /// context created block @property (nonatomic, copy) HippyContextCreatedBlock contextCreatedBlock; @@ -95,14 +71,6 @@ typedef void (^HippyContextCreatedBlock)(void); /// - Parameter inspectable: BOOL - (void)setInspecable:(BOOL)inspectable; -/// Set Uri loader -/// - Parameter uriLoader: vfs::UriLoader -- (void)setUriLoader:(std::weak_ptr)uriLoader; - -/// Get turbo object -/// - Parameter name: NSString -- (std::shared_ptr)JSTurboObjectWithName:(NSString *)name; - // TODO: 疑似已废弃 /** * Executes BatchedBridge.flushedQueue on JS thread and calls the given callback diff --git a/framework/ios/base/executors/HippyJSExecutor.mm b/framework/ios/base/executors/HippyJSExecutor.mm index b905c7b87a0..b646c3f67b6 100644 --- a/framework/ios/base/executors/HippyJSExecutor.mm +++ b/framework/ios/base/executors/HippyJSExecutor.mm @@ -21,6 +21,7 @@ */ #import "HippyJSExecutor.h" +#import "HippyJSExecutor+Internal.h" #import "VFSUriHandler.h" #import "HippyAssert.h" #import "HippyBundleURLProvider.h" @@ -81,6 +82,9 @@ @interface HippyJSExecutor () { + // The hippy scope + std::shared_ptr _pScope; + #ifdef JS_JSC BOOL _isInspectable; #endif //JS_JSC @@ -96,6 +100,8 @@ @interface HippyJSExecutor () { @implementation HippyJSExecutor +@synthesize pScope = _pScope; + - (void)setup { auto engine = [[HippyJSEnginesMapper defaultInstance] createJSEngineResourceForKey:self.enginekey]; const char *pName = [self.enginekey UTF8String] ?: ""; @@ -106,7 +112,7 @@ - (void)setup { @autoreleasepool { HippyJSExecutor *strongSelf = weakSelf; if (strongSelf) { - handleJsExcepiton(strongSelf->_pScope); + handleJsExcepiton(strongSelf.pScope); } } }; @@ -126,7 +132,7 @@ - (void)setup { } dispatch_semaphore_wait(scopeSemaphore, DISPATCH_TIME_FOREVER); - auto scope = strongSelf->_pScope; + auto scope = strongSelf.pScope; scope->CreateContext(); auto context = scope->GetContext(); auto global_object = context->GetGlobalObject(); @@ -179,7 +185,7 @@ - (void)setup { }]; } }); - self.pScope = scope; + _pScope = scope; dispatch_semaphore_signal(scopeSemaphore); #ifdef ENABLE_INSPECTOR @@ -237,7 +243,7 @@ - (void)invalidate { } #endif //JS_JSC self.pScope->WillExit(); - self.pScope = nullptr; + _pScope = nullptr; NSString *enginekey = self.enginekey; if (!enginekey) { return; @@ -373,7 +379,7 @@ - (void)setSandboxDirectory:(NSString *)directory { - (SharedCtxValuePtr)JSTurboObjectWithName:(NSString *)name { // create HostObject by name HippyOCTurboModule *turboModule = [self->_bridge turboModuleWithName:name]; - auto scope = self->_pScope; + auto scope = self.pScope; auto context = scope->GetContext(); if (!turboModule) { return context->CreateNull(); diff --git a/framework/ios/module/turbo/HippyOCTurboModule.mm b/framework/ios/module/turbo/HippyOCTurboModule.mm index 0741570dd92..8a8d3274449 100644 --- a/framework/ios/module/turbo/HippyOCTurboModule.mm +++ b/framework/ios/module/turbo/HippyOCTurboModule.mm @@ -24,7 +24,7 @@ #import "HippyOCTurboModule.h" #import "HippyOCTurboModule+Inner.h" #import "HippyTurboModuleManager.h" -#import "HippyJSExecutor.h" +#import "HippyJSExecutor+Internal.h" #import "HippyAssert.h" #import "HippyLog.h" #import "HippyUtils.h" diff --git a/framework/ios/module/turbo/HippyTurboModuleManager.mm b/framework/ios/module/turbo/HippyTurboModuleManager.mm index 8fb172ae1fd..7f4dfd72006 100644 --- a/framework/ios/module/turbo/HippyTurboModuleManager.mm +++ b/framework/ios/module/turbo/HippyTurboModuleManager.mm @@ -20,9 +20,10 @@ * */ -#import "HippyJSExecutor.h" -#import "HippyModuleData.h" + #import "HippyTurboModuleManager.h" +#import "HippyJSExecutor+Internal.h" +#import "HippyModuleData.h" #import "HippyAssert.h" #include diff --git a/hippy.podspec b/hippy.podspec index d69ed9e39a7..ef43c7e17ff 100644 --- a/hippy.podspec +++ b/hippy.podspec @@ -24,9 +24,6 @@ Pod::Spec.new do |s| s.source = {:git => 'https://github.com/Tencent/Hippy.git', :tag => s.version} s.platform = :ios s.ios.deployment_target = '11.0' - # Disable module compilation - s.module_map = false - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'NO' } s.prepare_command = <<-CMD ./xcodeinitscript.sh "#{layout_engine}" "#{js_engine}" @@ -58,6 +55,20 @@ Pod::Spec.new do |s| 'modules/vfs/ios/*.{h,m,mm}', 'modules/ios/image/*.{h,m,mm}', ] + framework.private_header_files = [ + 'framework/ios/**/*+Private.h', + 'framework/ios/**/*+Inne.h', + 'framework/ios/**/*+Internal.h', + 'framework/ios/**/HippyJSEnginesMapper.h', + 'framework/ios/**/NSObject+CtxValue.h', + 'framework/ios/**/HippyTurboModuleManager.h', + 'renderer/native/ios/**/*+Private.h', + 'renderer/native/ios/**/*+Internal.h', + 'renderer/native/ios/**/NativeRenderManager.h', + 'renderer/native/ios/**/HippyComponentMap.h', + 'renderer/native/ios/**/UIView+DirectionalLayout.h', + 'modules/vfs/ios/**/*.h', + ] framework.public_header_files = [ 'framework/ios/**/*.h', 'renderer/native/ios/**/*.h', @@ -74,6 +85,7 @@ Pod::Spec.new do |s| framework.dependency 'hippy/Base' framework.dependency 'hippy/JSDriver' framework.dependency 'hippy/VFS' + framework.dependency 'hippy/Dom' framework.dependency 'hippy/DomUtils' framework.dependency 'hippy/Footstone' framework.dependency 'hippy/FootstoneUtils' @@ -82,7 +94,7 @@ Pod::Spec.new do |s| s.subspec 'Footstone' do |footstone| footstone.libraries = 'c++' footstone.source_files = ['modules/footstone/**/*.{h,cc}'] - footstone.private_header_files = ['modules/footstone/**/*.h'] + footstone.project_header_files = ['modules/footstone/**/*.h'] footstone.exclude_files = ['modules/footstone/include/footstone/platform/adr', 'modules/footstone/src/platform/adr'] footstone.header_mappings_dir = 'modules/footstone/include/' @@ -99,7 +111,7 @@ Pod::Spec.new do |s| s.subspec 'FootstoneUtils' do |footstoneutils| footstoneutils.libraries = 'c++' footstoneutils.source_files = ['modules/ios/footstoneutils/*.{h,mm}'] - footstoneutils.private_header_files = ['modules/ios/footstoneutils/*.h'] + footstoneutils.project_header_files = ['modules/ios/footstoneutils/*.h'] footstoneutils.pod_target_xcconfig = { 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17', 'GCC_ENABLE_CPP_EXCEPTIONS' => false, @@ -112,7 +124,7 @@ Pod::Spec.new do |s| s.subspec 'VFS' do |vfs| vfs.libraries = 'c++' vfs.source_files = ['modules/vfs/native/**/*.{h,cc}'] - vfs.private_header_files = ['modules/vfs/native/include/**/*.h'] + vfs.project_header_files = ['modules/vfs/native/include/**/*.h'] vfs.header_mappings_dir = 'modules/vfs/native/include/' header_search_paths = '$(PODS_TARGET_SRCROOT)/modules/vfs/native/include/' @@ -197,7 +209,7 @@ Pod::Spec.new do |s| dom.libraries = 'c++' dom.source_files = dom_source_files - dom.private_header_files = ['dom/include/**/*.h'] + dom.project_header_files = ['dom/include/**/*.h'] dom.header_mappings_dir = 'dom/include/' dom.exclude_files = dom_exclude_files dom.pod_target_xcconfig = { diff --git a/framework/ios/module/loader/HippyBase64DataHandler.h b/modules/vfs/ios/HippyBase64DataHandler.h similarity index 100% rename from framework/ios/module/loader/HippyBase64DataHandler.h rename to modules/vfs/ios/HippyBase64DataHandler.h diff --git a/framework/ios/module/loader/HippyBase64DataHandler.mm b/modules/vfs/ios/HippyBase64DataHandler.mm similarity index 100% rename from framework/ios/module/loader/HippyBase64DataHandler.mm rename to modules/vfs/ios/HippyBase64DataHandler.mm diff --git a/framework/ios/module/loader/HippyBridge+VFSLoader.h b/modules/vfs/ios/HippyBridge+VFSLoader.h similarity index 100% rename from framework/ios/module/loader/HippyBridge+VFSLoader.h rename to modules/vfs/ios/HippyBridge+VFSLoader.h diff --git a/framework/ios/module/loader/HippyBridge+VFSLoader.mm b/modules/vfs/ios/HippyBridge+VFSLoader.mm similarity index 100% rename from framework/ios/module/loader/HippyBridge+VFSLoader.mm rename to modules/vfs/ios/HippyBridge+VFSLoader.mm diff --git a/framework/ios/module/loader/HippyFileHandler.h b/modules/vfs/ios/HippyFileHandler.h similarity index 100% rename from framework/ios/module/loader/HippyFileHandler.h rename to modules/vfs/ios/HippyFileHandler.h diff --git a/framework/ios/module/loader/HippyFileHandler.mm b/modules/vfs/ios/HippyFileHandler.mm similarity index 100% rename from framework/ios/module/loader/HippyFileHandler.mm rename to modules/vfs/ios/HippyFileHandler.mm diff --git a/renderer/native/ios/renderer/HippyRootView.mm b/renderer/native/ios/renderer/HippyRootView.mm index d08fed7628a..f140a9a869f 100644 --- a/renderer/native/ios/renderer/HippyRootView.mm +++ b/renderer/native/ios/renderer/HippyRootView.mm @@ -185,7 +185,7 @@ - (instancetype)initWithBridge:(HippyBridge *)bridge } // 抛出业务包(BusinessBundle aka SecondaryBundle)加载完成通知,for hippy2兼容 - NSMutableDictionary *userInfo = @{ kHippyNotiBundleUrlKey: url, + NSMutableDictionary *userInfo = @{ kHippyNotiBundleUrlKey: url ?: @"", kHippyNotiBridgeKey: strongSelf.bridge }.mutableCopy; if (error) { [userInfo setObject:error forKey:kHippyNotiErrorKey]; } HIPPY_IGNORE_WARNING_BEGIN(-Wdeprecated) diff --git a/renderer/native/ios/renderer/HippyUIManager.h b/renderer/native/ios/renderer/HippyUIManager.h index 63d88dd132e..f39449098ec 100644 --- a/renderer/native/ios/renderer/HippyUIManager.h +++ b/renderer/native/ios/renderer/HippyUIManager.h @@ -68,7 +68,7 @@ HIPPY_EXTERN NSString *const HippyUIManagerDidEndBatchNotification; @interface HippyUIManager : NSObject /// HippyBridge instance -@property (nonatomic, weak) HippyBridge *bridge; +@property (nonatomic, weak, readonly) HippyBridge *bridge; /// View Registry of all nodes @property (nonatomic, readonly) HippyComponentMap *viewRegistry; @@ -78,6 +78,11 @@ HIPPY_EXTERN NSString *const HippyUIManagerDidEndBatchNotification; /// default is NO. @property (nonatomic, assign) BOOL uiCreationLazilyEnabled; +/// Init method +/// - Parameter bridge: HippyBridge +- (instancetype)initWithBridge:(HippyBridge *)bridge NS_DESIGNATED_INITIALIZER; +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)new NS_UNAVAILABLE; /// Gets the view associated with a hippyTag. /// - Parameters: diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index cddf92e26d2..5cfd1b514aa 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -206,12 +206,6 @@ @interface HippyUIManager() { -#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 @@ -220,9 +214,10 @@ @implementation HippyUIManager #pragma mark Life cycle -- (instancetype)init { +- (instancetype)initWithBridge:(HippyBridge *)bridge { self = [super init]; if (self) { + _bridge = bridge; [self initContext]; } return self; @@ -671,9 +666,8 @@ - (void)updateView:(nonnull NSNumber *)componentTag }]; } -#pragma mark - Render Context Implementation - - (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName { + HippyBridge *strongBridge = self.bridge; if (!_viewManagers) { _viewManagers = [NSMutableDictionary dictionary]; if (_extraComponents) { @@ -686,7 +680,7 @@ - (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName { [_viewManagers setObject:cls forKey:viewName]; } } - NSArray *classes = HippyGetViewManagerClasses(self.bridge); + NSArray *classes = HippyGetViewManagerClasses(strongBridge); NSMutableDictionary *defaultViewManagerClasses = [NSMutableDictionary dictionaryWithCapacity:[classes count]]; for (Class cls in classes) { NSString *viewName = viewNameFromViewManagerClass(cls); @@ -701,7 +695,7 @@ - (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName { id object = [_viewManagers objectForKey:viewName]; if (object_isClass(object)) { HippyViewManager *viewManager = [object new]; - viewManager.bridge = self.bridge; + viewManager.bridge = strongBridge; NSAssert([viewManager isKindOfClass:[HippyViewManager class]], @"Must be a HippyViewManager instance"); [_viewManagers setObject:viewManager forKey:viewName]; object = viewManager; @@ -781,12 +775,6 @@ - (void)createRenderNodes:(std::vector> &&)nodes if (!strongRootNode) { return; } -#if HIPPY_DEBUG - auto &nodeMap = _domNodesMap[strongRootNode->GetId()]; - for (auto node : nodes) { - nodeMap[node->GetId()] = node; - } -#endif NSNumber *rootNodeTag = @(strongRootNode->GetId()); std::lock_guard lock([self renderQueueLock]); NativeRenderViewsRelation *manager = [[NativeRenderViewsRelation alloc] init]; @@ -877,12 +865,6 @@ - (void)updateRenderNodes:(std::vector>&&)nodes if (!strongRootNode) { return; } -#if HIPPY_DEBUG - auto &nodeMap = _domNodesMap[strongRootNode->GetId()]; - for (auto node : nodes) { - nodeMap[node->GetId()] = node; - } -#endif std::lock_guard lock([self renderQueueLock]); NSNumber *rootTag = @(strongRootNode->GetId()); for (const auto &node : nodes) { @@ -909,12 +891,6 @@ - (void)deleteRenderNodesIds:(std::vector> &&)no if (!strongRootNode) { return; } -#if HIPPY_DEBUG - auto &nodeMap = _domNodesMap[strongRootNode->GetId()]; - for (auto node : nodes) { - nodeMap[node->GetId()] = nullptr; - } -#endif std::lock_guard lock([self renderQueueLock]); NSNumber *rootTag = @(strongRootNode->GetId()); NSDictionary *currentRegistry = [_shadowViewRegistry componentsForRootTag:rootTag]; @@ -1508,26 +1484,6 @@ - (void)domEventDidHandle:(const std::string &)eventName forNode:(int32_t)tag on // no op } -#pragma mark Debug Methods -#if HIPPY_DEBUG -- (std::shared_ptr)domNodeForTag:(int32_t)dom_tag onRootNode:(int32_t)root_tag { - auto find = _domNodesMap.find(root_tag); - if (_domNodesMap.end() == find) { - return nullptr; - } - auto map = find->second; - auto domFind = map.find(dom_tag); - if (map.end() == domFind) { - return nullptr; - } - return domFind->second; -} -- (std::vector>)childrenForNodeTag:(int32_t)tag onRootNode:(int32_t)root_tag { - auto node = [self domNodeForTag:tag onRootNode:root_tag]; - return node ? node->GetChildren() : std::vector>{}; -} -#endif - @end diff --git a/renderer/native/ios/renderer/component/text/HippyShadowText+Internal.h b/renderer/native/ios/renderer/component/text/HippyShadowText+Internal.h new file mode 100644 index 00000000000..85c620ddf02 --- /dev/null +++ b/renderer/native/ios/renderer/component/text/HippyShadowText+Internal.h @@ -0,0 +1,44 @@ +/*! + * 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. + */ + + +#import "HippyShadowText.h" + +namespace hippy { +inline namespace dom { +enum class LayoutMeasureMode; +struct LayoutSize; +} +} + +NS_ASSUME_NONNULL_BEGIN + +@interface HippyShadowText (Internal) + +hippy::LayoutSize textMeasureFunc(HippyShadowText *weakShadowText, + float width, hippy::LayoutMeasureMode widthMeasureMode, + float height, hippy::LayoutMeasureMode heightMeasureMode, + void *layoutContext); + +@end + +NS_ASSUME_NONNULL_END diff --git a/renderer/native/ios/renderer/component/text/HippyShadowText.h b/renderer/native/ios/renderer/component/text/HippyShadowText.h index 0ab41e6d889..a9be9a1525b 100644 --- a/renderer/native/ios/renderer/component/text/HippyShadowText.h +++ b/renderer/native/ios/renderer/component/text/HippyShadowText.h @@ -29,27 +29,17 @@ typedef NS_ENUM(NSInteger, HippySizeComparison) { HippySizeWithinRange, }; -namespace hippy { -inline namespace dom { -enum class LayoutMeasureMode; -struct LayoutSize; -} -} extern NSAttributedStringKey const HippyIsHighlightedAttributeName; extern NSAttributedStringKey const HippyTagAttributeName; extern NSAttributedStringKey const HippyShadowViewAttributeName; -hippy::LayoutSize textMeasureFunc(float width, hippy::LayoutMeasureMode widthMeasureMode, - __unused float height, - __unused hippy::LayoutMeasureMode heightMeasureMode, - void *layoutContext); +/// Text's ShadowNode @interface HippyShadowText : HippyShadowView { @protected NSTextStorage *_cachedTextStorage; CGFloat _cachedTextStorageWidth; - hippy::LayoutMeasureMode _cachedTextStorageWidthMode; NSAttributedString *_cachedAttributedString; CGFloat _effectiveLetterSpacing; BOOL _textAlignSet; diff --git a/renderer/native/ios/renderer/component/text/HippyShadowText.mm b/renderer/native/ios/renderer/component/text/HippyShadowText.mm index b8d3d4b59df..f1fdc56bfb2 100644 --- a/renderer/native/ios/renderer/component/text/HippyShadowText.mm +++ b/renderer/native/ios/renderer/component/text/HippyShadowText.mm @@ -89,6 +89,7 @@ @interface HippyShadowText () { BOOL _isNestedText; // Indicates whether Text is nested, for speeding up typesetting calculations BOOL _needRelayoutText; // special styles require two layouts, eg. verticalAlign etc + hippy::LayoutMeasureMode _cachedTextStorageWidthMode; // cached width mode when building text storage } @end @@ -96,9 +97,10 @@ @interface HippyShadowText () @implementation HippyShadowText -hippy::LayoutSize textMeasureFunc( - HippyShadowText *weakShadowText, float width,hippy::LayoutMeasureMode widthMeasureMode, - float height, hippy::LayoutMeasureMode heightMeasureMode, void *layoutContext) { +hippy::LayoutSize textMeasureFunc(HippyShadowText *weakShadowText, + float width, hippy::LayoutMeasureMode widthMeasureMode, + float height, hippy::LayoutMeasureMode heightMeasureMode, + void *layoutContext) { hippy::LayoutSize retSize; HippyShadowText *strongShadowText = weakShadowText; if (strongShadowText) { diff --git a/renderer/native/ios/renderer/component/text/HippyTextManager.mm b/renderer/native/ios/renderer/component/text/HippyTextManager.mm index bc2159baf1a..edd534a17ea 100644 --- a/renderer/native/ios/renderer/component/text/HippyTextManager.mm +++ b/renderer/native/ios/renderer/component/text/HippyTextManager.mm @@ -37,11 +37,6 @@ static void collectDirtyNonTextDescendants(HippyShadowText *renderObject, NSMuta } } -@interface HippyShadowText (Private) -// hplayout -- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(hippy::LayoutMeasureMode)widthMode; -@end - @implementation HippyTextManager HIPPY_EXPORT_MODULE(Text) diff --git a/tests/ios/HippyUIManagerTest.mm b/tests/ios/HippyUIManagerTest.mm index 1c28442fecd..5255a3f278e 100644 --- a/tests/ios/HippyUIManagerTest.mm +++ b/tests/ios/HippyUIManagerTest.mm @@ -49,7 +49,8 @@ - (void)tearDown { } - (void)testGetComponentDataForViewName { - HippyUIManager *manager = [[HippyUIManager alloc] init]; + HippyBridge *bridge = [[HippyBridge alloc] init]; + HippyUIManager *manager = [[HippyUIManager alloc] initWithBridge:bridge]; [manager registerExtraComponent:@[ HippyViewManager.class ]]; XCTAssertNil([manager componentDataForViewName:nil]); diff --git a/tests/ios/HippyUIViewCategoryTest.m b/tests/ios/HippyUIViewCategoryTest.m index d6fb521c9b7..d1a879d1a31 100644 --- a/tests/ios/HippyUIViewCategoryTest.m +++ b/tests/ios/HippyUIViewCategoryTest.m @@ -63,8 +63,8 @@ - (void)testGetHippyRootView { - (void)testGetHippyUIManager { UIView *testView = [UIView new]; XCTAssertNil([testView uiManager]); - - HippyUIManager *uiManager = [[HippyUIManager alloc] init]; + HippyBridge *bridge = [[HippyBridge alloc] init]; + HippyUIManager *uiManager = [[HippyUIManager alloc] initWithBridge:bridge]; XCTAssertNoThrow(testView.uiManager = uiManager); XCTAssertTrue(testView.uiManager == uiManager); }