Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ios): remove all context wrapper classes #3994

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions framework/ios/base/bridge/HippyBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,11 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass);
/// All registered bridge module classes.
@property (nonatomic, copy, readonly) NSArray<Class> *moduleClasses;

- (NSString *)moduleConfig;
/// Get all native module info.
- (NSDictionary *)nativeModuleConfig;

/// Get config info for given module name
/// - Parameter moduleName: name of module
- (NSArray *)configForModuleName:(NSString *)moduleName;

- (BOOL)moduleSetupComplete;
Expand Down Expand Up @@ -350,9 +353,8 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass);
*/
- (BOOL)moduleIsInitialized:(Class)moduleClass;

/**
* Get the turbo module for a given name.
*/
/// Get turbo module by name.
/// - Parameter name: name of turbo module
- (id)turboModuleWithName:(NSString *)name;


Expand Down
86 changes: 42 additions & 44 deletions framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#import "HippyBundleLoadOperation.h"
#import "HippyBundleExecutionOperation.h"
#import "HippyBundleOperationQueue.h"
#import "HippyContextWrapper.h"
#import "HippyDeviceBaseInfo.h"
#import "HippyDisplayLink.h"
#import "HippyEventDispatcher.h"
Expand Down Expand Up @@ -103,6 +102,10 @@
static NSString *const HippyNativeGlobalKeyLocalization = @"Localization";
static NSString *const HippyNativeGlobalKeyNightMode = @"NightMode";

// key of module config info for js side
static NSString *const kHippyRemoteModuleConfigKey = @"remoteModuleConfig";
static NSString *const kHippyBatchedBridgeConfigKey = @"__hpBatchedBridgeConfig";


typedef NS_ENUM(NSUInteger, HippyBridgeFields) {
HippyBridgeFieldRequestModuleIDs = 0,
Expand Down Expand Up @@ -309,6 +312,9 @@ - (void)setUpNativeRenderManager {
return _uriLoader;
}


#pragma mark - Module Management

- (NSArray<Class> *)moduleClasses {
return _moduleSetup.moduleClasses;
}
Expand Down Expand Up @@ -345,6 +351,35 @@ - (BOOL)moduleIsInitialized:(Class)moduleClass {
return [_moduleSetup isModuleInitialized:moduleClass];
}

- (BOOL)moduleSetupComplete {
return _moduleSetup.isModuleSetupComplete;
}

- (NSDictionary *)nativeModuleConfig {
NSMutableArray<NSArray *> *config = [NSMutableArray new];
for (HippyModuleData *moduleData in [_moduleSetup moduleDataByID]) {
NSArray *moduleDataConfig = [moduleData config];
[config addObject:HippyNullIfNil(moduleDataConfig)];
}
return @{ kHippyRemoteModuleConfigKey : config };
}

- (NSArray *)configForModuleName:(NSString *)moduleName {
HippyModuleData *moduleData = [_moduleSetup moduleDataByName][moduleName];
return moduleData.config;
}

- (HippyOCTurboModule *)turboModuleWithName:(NSString *)name {
if (!self.enableTurbo || name.length <= 0) {
return nil;
}

if (!self.turboModuleManager) {
self.turboModuleManager = [[HippyTurboModuleManager alloc] initWithBridge:self];
}
return [self.turboModuleManager turboModuleWithName:name];
}


#pragma mark - Image Config Related

Expand Down Expand Up @@ -412,12 +447,14 @@ - (void)setUp {
__weak HippyBridge *weakSelf = self;
_moduleSetup = [[HippyModulesSetup alloc] initWithBridge:self extraProviderModulesBlock:_moduleProvider];
_javaScriptExecutor = [[HippyJSExecutor alloc] initWithEngineKey:self.engineKey bridge:self];
_javaScriptExecutor.contextCreatedBlock = ^(id<HippyContextWrapper> ctxWrapper){
HippyBridge *strongSelf = weakSelf;

_javaScriptExecutor.contextCreatedBlock = ^(){
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (strongSelf) {
dispatch_semaphore_wait(strongSelf.moduleSemaphore, DISPATCH_TIME_FOREVER);
NSString *moduleConfig = [strongSelf moduleConfig];
[ctxWrapper createGlobalObject:@"__hpBatchedBridgeConfig" withJsonValue:moduleConfig];
NSDictionary *nativeModuleConfig = [strongSelf nativeModuleConfig];
[strongSelf.javaScriptExecutor injectObjectSync:nativeModuleConfig
asGlobalObjectNamed:kHippyBatchedBridgeConfigKey callback:nil];
#if HIPPY_DEV
//default is yes when debug mode
[strongSelf setInspectable:YES];
Expand Down Expand Up @@ -1016,10 +1053,6 @@ - (BOOL)isLoading {
return 0 == count;
}

- (BOOL)moduleSetupComplete {
return _moduleSetup.isModuleSetupComplete;
}

- (void)invalidate {
HippyLogInfo(@"[Hippy_OC_Log][Life_Circle],%@ invalide %p", NSStringFromClass([self class]), self);
if (![self isValid]) {
Expand Down Expand Up @@ -1163,52 +1196,17 @@ - (void)setOSNightMode:(BOOL)isOSNightMode withRootViewTag:(nonnull NSNumber *)r

#pragma mark -

- (NSString *)moduleConfig {
NSMutableArray<NSArray *> *config = [NSMutableArray new];
for (HippyModuleData *moduleData in [_moduleSetup moduleDataByID]) {
NSArray *moduleDataConfig = [moduleData config];
[config addObject:HippyNullIfNil(moduleDataConfig)];
}
id jsonArray = @{
@"remoteModuleConfig": config,
};
return HippyJSONStringify(jsonArray, NULL);
}

- (void)setRedBoxShowEnabled:(BOOL)enabled {
#if HIPPY_DEBUG
HippyRedBox *redBox = [self redBox];
redBox.showEnabled = enabled;
#endif // HIPPY_DEBUG
}

- (HippyOCTurboModule *)turboModuleWithName:(NSString *)name {
if (!self.enableTurbo) {
return nil;
}

if (name.length <= 0) {
return nil;
}

if(!self.turboModuleManager) {
self.turboModuleManager = [[HippyTurboModuleManager alloc] initWithBridge:self];
}

// getTurboModule
HippyOCTurboModule *turboModule = [self.turboModuleManager turboModuleWithName:name];
return turboModule;
}

- (void)registerModuleForFrameUpdates:(id<HippyBridgeModule>)module withModuleData:(HippyModuleData *)moduleData {
[_displayLink registerModuleForFrameUpdates:module withModuleData:moduleData];
}

- (NSArray *)configForModuleName:(NSString *)moduleName {
HippyModuleData *moduleData = [_moduleSetup moduleDataByName][moduleName];
return moduleData.config;
}

- (void)setSandboxDirectory:(NSURL *)sandboxDirectory {
if (![_sandboxDirectory isEqual:sandboxDirectory]) {
_sandboxDirectory = sandboxDirectory;
Expand Down
92 changes: 0 additions & 92 deletions framework/ios/base/enginewrapper/HippyContextWrapper.h

This file was deleted.

36 changes: 0 additions & 36 deletions framework/ios/base/enginewrapper/jsc/HippyJSCContextWrapper.h

This file was deleted.

Loading
Loading