Add API for synchronous rendering to Panel
This commit is contained in:
@@ -68,11 +68,15 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)onHidden;
|
||||
|
||||
-(void)onEnvChanged;
|
||||
- (void)onEnvChanged;
|
||||
|
||||
- (DoricViewNode *)targetViewNode:(NSString *)viewId;
|
||||
|
||||
- (void)dispatchToMainQueue:(_Nonnull dispatch_block_t)block;
|
||||
|
||||
- (DoricAsyncResult *)pureCallEntity:(NSString *)method withArgumentsArray:(NSArray *)args;
|
||||
|
||||
- (void)renderSynchronously;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -28,6 +28,8 @@
|
||||
#import "DoricNativeDriver.h"
|
||||
#import "DoricUtil.h"
|
||||
#import "DoricSingleton.h"
|
||||
#import "DoricShaderPlugin.h"
|
||||
#import <JavaScriptCore/JavaScriptCore.h>
|
||||
|
||||
@implementation DoricContext
|
||||
|
||||
@@ -154,4 +156,36 @@ - (void)dispatchToMainQueue:(_Nonnull dispatch_block_t)block {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (DoricAsyncResult *)pureCallEntity:(NSString *)method withArgumentsArray:(NSArray *)args {
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
[array addObject:self.contextId];
|
||||
[array addObject:method];
|
||||
[array addObjectsFromArray:args];
|
||||
DoricAsyncResult *ret = [self.driver invokeDoricMethod:DORIC_CONTEXT_INVOKE_PURE argumentsArray:array];
|
||||
__weak typeof(self) __self = self;
|
||||
ret.exceptionCallback = ^(NSException *e) {
|
||||
__strong typeof(__self) self = __self;
|
||||
[self.driver.registry
|
||||
onException:e
|
||||
inContext:self];
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (void)renderSynchronously {
|
||||
DoricAsyncResult *ret = [self pureCallEntity:DORIC_ENTITY_FETCH_DIRTY_DATA withArgumentsArray:@[]];
|
||||
NSArray *array = [ret waitUntilResult:^(JSValue *models) {
|
||||
return [models toArray];
|
||||
}];
|
||||
DoricShaderPlugin *shaderPlugin = self.pluginInstanceMap[@"Shader"];
|
||||
if (!shaderPlugin) {
|
||||
shaderPlugin = [[DoricShaderPlugin alloc] initWithContext:self];
|
||||
self.pluginInstanceMap[@"Shader"] = shaderPlugin;
|
||||
}
|
||||
for (NSDictionary *model in array) {
|
||||
[shaderPlugin render:model withPromise:nil];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -27,4 +27,6 @@
|
||||
@property(nonatomic, strong) void (^frameChangedBlock)(CGSize frameSize);
|
||||
|
||||
- (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extra;
|
||||
|
||||
- (void)renderSynchronously;
|
||||
@end
|
@@ -19,6 +19,7 @@
|
||||
|
||||
#import "DoricPanel.h"
|
||||
#import "Doric.h"
|
||||
#import "DoricConstant.h"
|
||||
|
||||
@interface DoricPanel ()
|
||||
@property(nonatomic, assign) CGFloat renderedWidth;
|
||||
@@ -79,4 +80,17 @@ - (void)viewDidDisappear:(BOOL)animated {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)renderSynchronously {
|
||||
[self.doricContext renderSynchronously];
|
||||
CGSize newSize = self.doricContext.rootNode.view.frame.size;
|
||||
if (self.renderedWidth != newSize.width || self.renderedWidth != newSize.height) {
|
||||
self.renderedWidth = newSize.width;
|
||||
self.renderedHeight = newSize.height;
|
||||
self.view.width = newSize.width;
|
||||
self.view.height = newSize.height;
|
||||
if (self.frameChangedBlock) {
|
||||
self.frameChangedBlock(newSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
@@ -23,10 +23,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricShaderPlugin : DoricNativePlugin
|
||||
|
||||
- (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -70,3 +70,5 @@ extern NSString *const DORIC_ENTITY_HIDDEN;
|
||||
extern NSString *const DORIC_ENTITY_BUILD;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_ENV_CHANGE;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_FETCH_DIRTY_DATA;
|
||||
|
@@ -88,3 +88,5 @@
|
||||
NSString *const DORIC_ENTITY_BUILD = @"__build__";
|
||||
|
||||
NSString *const DORIC_ENTITY_ENV_CHANGE = @"__onEnvChanged__";
|
||||
|
||||
NSString *const DORIC_ENTITY_FETCH_DIRTY_DATA = @"__fetchEffectiveData__";
|
||||
|
Reference in New Issue
Block a user