Skip to content

Commit

Permalink
feat(ios): modular header import support
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Sep 13, 2024
1 parent 15b0c83 commit 5088247
Show file tree
Hide file tree
Showing 24 changed files with 159 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@
#import "HippyDemoViewController.h"
#import "UIViewController+Title.h"
#import "HippyPageCache.h"

#import <hippy/HippyBridge.h>
#import <hippy/HippyRootView.h>
#import <hippy/HippyLog.h>
#import <hippy/HippyAssert.h>
#import <hippy/UIView+Hippy.h>
#import <hippy/HippyMethodInterceptorProtocol.h>
@import hippy;


@interface HippyDemoViewController () <HippyMethodInterceptorProtocol, HippyBridgeDelegate, HippyRootViewDelegate> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#import "TurboConfig.h"
#import "HippyDefines.h"
#import "HippyDefines.h"

@interface TurboConfig ()

Expand Down
5 changes: 4 additions & 1 deletion framework/examples/ios-demo/podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion framework/ios/base/bridge/HippyBridge+PerformanceAPI.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

#import "HippyBridge+PerformanceAPI.h"
#import "HippyJSExecutor.h"
#import "HippyJSExecutor+Internal.h"
#import "HippyLog.h"
#import "driver/scope.h"

Expand Down
2 changes: 1 addition & 1 deletion framework/ios/base/bridge/HippyBridge+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define HippyBridge_Private_h

#import "HippyBridge.h"
#import "footstone/time_point.h"
#include "footstone/time_point.h"
#include <memory>

class VFSUriLoader;
Expand Down
2 changes: 1 addition & 1 deletion framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
62 changes: 62 additions & 0 deletions framework/ios/base/executors/HippyJSExecutor+Internal.h
Original file line number Diff line number Diff line change
@@ -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 <memory>

namespace hippy {
inline namespace driver {
inline namespace napi {
class CtxValue;
}
class Scope;
}
inline namespace vfs {
class UriLoader;
}
}


@protocol HippyJSExecutorInternal <NSObject>

/// hippy scope
@property (atomic, readonly) std::shared_ptr<hippy::Scope> pScope;

/// Set Uri loader
/// - Parameter uriLoader: vfs::UriLoader
- (void)setUriLoader:(std::weak_ptr<hippy::vfs::UriLoader>)uriLoader;

/// Get turbo object
/// - Parameter name: NSString
- (std::shared_ptr<hippy::napi::CtxValue>)JSTurboObjectWithName:(NSString *)name;

@end

@interface HippyJSExecutor (Internal) <HippyJSExecutorInternal>

@end


#endif /* HippyJSExecutor_Internal_h */
34 changes: 1 addition & 33 deletions framework/ios/base/executors/HippyJSExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,15 @@
#import "HippyDefines.h"
#import "HippyDefines.h"
#import "HippyInvalidating.h"
#include <memory>

@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.
*/
Expand All @@ -68,9 +47,6 @@ typedef void (^HippyContextCreatedBlock)(void);
/// EngineKey
@property (nonatomic, copy) NSString *enginekey;

/// hippy scope
@property (atomic, assign) std::shared_ptr<hippy::Scope> pScope;

/// context created block
@property (nonatomic, copy) HippyContextCreatedBlock contextCreatedBlock;

Expand All @@ -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<hippy::vfs::UriLoader>)uriLoader;

/// Get turbo object
/// - Parameter name: NSString
- (std::shared_ptr<hippy::napi::CtxValue>)JSTurboObjectWithName:(NSString *)name;

// TODO: 疑似已废弃
/**
* Executes BatchedBridge.flushedQueue on JS thread and calls the given callback
Expand Down
16 changes: 11 additions & 5 deletions framework/ios/base/executors/HippyJSExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#import "HippyJSExecutor.h"
#import "HippyJSExecutor+Internal.h"
#import "VFSUriHandler.h"
#import "HippyAssert.h"
#import "HippyBundleURLProvider.h"
Expand Down Expand Up @@ -81,6 +82,9 @@


@interface HippyJSExecutor () {
// The hippy scope
std::shared_ptr<hippy::Scope> _pScope;

#ifdef JS_JSC
BOOL _isInspectable;
#endif //JS_JSC
Expand All @@ -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] ?: "";
Expand All @@ -106,7 +112,7 @@ - (void)setup {
@autoreleasepool {
HippyJSExecutor *strongSelf = weakSelf;
if (strongSelf) {
handleJsExcepiton(strongSelf->_pScope);
handleJsExcepiton(strongSelf.pScope);
}
}
};
Expand All @@ -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();
Expand Down Expand Up @@ -179,7 +185,7 @@ - (void)setup {
}];
}
});
self.pScope = scope;
_pScope = scope;
dispatch_semaphore_signal(scopeSemaphore);

#ifdef ENABLE_INSPECTOR
Expand Down Expand Up @@ -237,7 +243,7 @@ - (void)invalidate {
}
#endif //JS_JSC
self.pScope->WillExit();
self.pScope = nullptr;
_pScope = nullptr;
NSString *enginekey = self.enginekey;
if (!enginekey) {
return;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion framework/ios/module/turbo/HippyOCTurboModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions framework/ios/module/turbo/HippyTurboModuleManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
*
*/

#import "HippyJSExecutor.h"
#import "HippyModuleData.h"

#import "HippyTurboModuleManager.h"
#import "HippyJSExecutor+Internal.h"
#import "HippyModuleData.h"
#import "HippyAssert.h"

#include <unordered_map>
Expand Down
26 changes: 19 additions & 7 deletions hippy.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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',
Expand All @@ -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'
Expand All @@ -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/'

Expand All @@ -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,
Expand All @@ -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/'
Expand Down Expand Up @@ -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 = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5088247

Please sign in to comment.