Skip to content

Commit

Permalink
refactor(ios): remove all context wrapper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Aug 15, 2024
1 parent 9ba8426 commit c8a80f5
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 2,163 deletions.
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

0 comments on commit c8a80f5

Please sign in to comment.