feat: Native add legacy mode
This commit is contained in:
parent
64a370c701
commit
7a126531af
@ -92,4 +92,8 @@ public class Doric {
|
|||||||
public static DoricJSLoaderManager getJSLoaderManager() {
|
public static DoricJSLoaderManager getJSLoaderManager() {
|
||||||
return DoricSingleton.getInstance().getJSLoaderManager();
|
return DoricSingleton.getInstance().getJSLoaderManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setLegacyMode(boolean legacyMode) {
|
||||||
|
DoricSingleton.getInstance().legacyMode = legacyMode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ public class DoricSingleton {
|
|||||||
boolean enableRenderSnapshot = false;
|
boolean enableRenderSnapshot = false;
|
||||||
private DoricNativeDriver nativeDriver;
|
private DoricNativeDriver nativeDriver;
|
||||||
private final DoricContextManager doricContextManager = new DoricContextManager();
|
private final DoricContextManager doricContextManager = new DoricContextManager();
|
||||||
|
public boolean legacyMode = false;
|
||||||
|
|
||||||
private static class Inner {
|
private static class Inner {
|
||||||
private static final DoricSingleton sInstance = new DoricSingleton();
|
private static final DoricSingleton sInstance = new DoricSingleton();
|
||||||
|
@ -43,6 +43,7 @@ import pub.doric.Doric;
|
|||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
import pub.doric.DoricContextManager;
|
import pub.doric.DoricContextManager;
|
||||||
import pub.doric.DoricRegistry;
|
import pub.doric.DoricRegistry;
|
||||||
|
import pub.doric.DoricSingleton;
|
||||||
import pub.doric.IDoricMonitor;
|
import pub.doric.IDoricMonitor;
|
||||||
import pub.doric.extension.bridge.DoricBridgeExtension;
|
import pub.doric.extension.bridge.DoricBridgeExtension;
|
||||||
import pub.doric.extension.timer.DoricTimerExtension;
|
import pub.doric.extension.timer.DoricTimerExtension;
|
||||||
@ -109,14 +110,14 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
e.printStackTrace(new PrintWriter(stringWriter));
|
e.printStackTrace(new PrintWriter(stringWriter));
|
||||||
mDoricRegistry.onLog(Log.ERROR, stringWriter.toString());
|
mDoricRegistry.onLog(Log.ERROR, stringWriter.toString());
|
||||||
//In case some unexpected errors happened
|
//In case some unexpected errors happened
|
||||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
// mDoricRegistry.onLog(Log.WARN, "Use DoricWebViewJSExecutor");
|
mDoricRegistry.onLog(Log.WARN, "Use DoricWebViewJSExecutor");
|
||||||
// mDoricJSE = new DoricWebViewJSExecutor(Doric.application());
|
mDoricJSE = new DoricWebViewJSExecutor(Doric.application());
|
||||||
// loadBuiltinJS("doric-web.js");
|
loadBuiltinJS("doric-web.js");
|
||||||
// } else {
|
} else {
|
||||||
mDoricRegistry.onLog(Log.WARN, "Use DoricWebShellJSExecutor");
|
mDoricRegistry.onLog(Log.WARN, "Use DoricWebShellJSExecutor");
|
||||||
mDoricJSE = new DoricWebShellJSExecutor(Doric.application());
|
mDoricJSE = new DoricWebShellJSExecutor(Doric.application());
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,9 +261,10 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
|
|
||||||
private void initDoricRuntime() {
|
private void initDoricRuntime() {
|
||||||
try {
|
try {
|
||||||
loadBuiltinJS(DoricConstant.DORIC_BUNDLE_SANDBOX);
|
boolean legacy = DoricSingleton.getInstance().legacyMode;
|
||||||
|
loadBuiltinJS(legacy ? DoricConstant.DORIC_BUNDLE_SANDBOX_ES5 : DoricConstant.DORIC_BUNDLE_SANDBOX);
|
||||||
String libName = DoricConstant.DORIC_MODULE_LIB;
|
String libName = DoricConstant.DORIC_MODULE_LIB;
|
||||||
String libJS = DoricUtils.readAssetFile(DoricConstant.DORIC_BUNDLE_LIB);
|
String libJS = DoricUtils.readAssetFile(legacy ? DoricConstant.DORIC_BUNDLE_LIB_ES5 : DoricConstant.DORIC_BUNDLE_LIB);
|
||||||
mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
|
mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mDoricRegistry.onException(null, e);
|
mDoricRegistry.onException(null, e);
|
||||||
|
@ -22,7 +22,9 @@ package pub.doric.utils;
|
|||||||
*/
|
*/
|
||||||
public class DoricConstant {
|
public class DoricConstant {
|
||||||
public static final String DORIC_BUNDLE_SANDBOX = "doric-sandbox.js";
|
public static final String DORIC_BUNDLE_SANDBOX = "doric-sandbox.js";
|
||||||
|
public static final String DORIC_BUNDLE_SANDBOX_ES5 = "doric-sandbox.es5.js";
|
||||||
public static final String DORIC_BUNDLE_LIB = "doric-lib.js";
|
public static final String DORIC_BUNDLE_LIB = "doric-lib.js";
|
||||||
|
public static final String DORIC_BUNDLE_LIB_ES5 = "doric-lib.es5.js";
|
||||||
public static final String DORIC_MODULE_LIB = "doric";
|
public static final String DORIC_MODULE_LIB = "doric";
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,4 +61,9 @@
|
|||||||
+ (void)setEnvironmentValue:(NSDictionary *)value;
|
+ (void)setEnvironmentValue:(NSDictionary *)value;
|
||||||
|
|
||||||
+ (DoricJSLoaderManager *)jsLoaderManager;
|
+ (DoricJSLoaderManager *)jsLoaderManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set legacy mode to compat es5 code
|
||||||
|
* */
|
||||||
|
+ (void)setLegacyMode:(BOOL)legacy;
|
||||||
@end
|
@end
|
@ -55,4 +55,8 @@ + (void)setEnvironmentValue:(NSDictionary *)value {
|
|||||||
+ (DoricJSLoaderManager *)jsLoaderManager {
|
+ (DoricJSLoaderManager *)jsLoaderManager {
|
||||||
return DoricSingleton.instance.jsLoaderManager;
|
return DoricSingleton.instance.jsLoaderManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (void)setLegacyMode:(BOOL)legacy {
|
||||||
|
[DoricSingleton.instance setLegacyMode:legacy];
|
||||||
|
}
|
||||||
@end
|
@end
|
@ -32,6 +32,7 @@
|
|||||||
@property(nonatomic, strong) NSMutableDictionary *envDic;
|
@property(nonatomic, strong) NSMutableDictionary *envDic;
|
||||||
@property(nonatomic, assign) BOOL enablePerformance;
|
@property(nonatomic, assign) BOOL enablePerformance;
|
||||||
@property(nonatomic, assign) BOOL enableRecordSnapshot;
|
@property(nonatomic, assign) BOOL enableRecordSnapshot;
|
||||||
|
@property(nonatomic, assign) BOOL legacyMode;
|
||||||
@property(nonatomic, strong) DoricJSLoaderManager *jsLoaderManager;
|
@property(nonatomic, strong) DoricJSLoaderManager *jsLoaderManager;
|
||||||
@property(nonatomic, strong) DoricNativeDriver *nativeDriver;
|
@property(nonatomic, strong) DoricNativeDriver *nativeDriver;
|
||||||
@property(nonatomic, strong) DoricContextManager *contextManager;
|
@property(nonatomic, strong) DoricContextManager *contextManager;
|
||||||
|
@ -38,6 +38,7 @@ - (instancetype)init {
|
|||||||
valueOptions:NSPointerFunctionsWeakMemory
|
valueOptions:NSPointerFunctionsWeakMemory
|
||||||
capacity:0];
|
capacity:0];
|
||||||
_bundles = [NSMutableDictionary new];
|
_bundles = [NSMutableDictionary new];
|
||||||
|
_legacyMode = NO;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#import "DoricContextManager.h"
|
#import "DoricContextManager.h"
|
||||||
#import "DoricPerformanceProfile.h"
|
#import "DoricPerformanceProfile.h"
|
||||||
#import "JSValue+Doric.h"
|
#import "JSValue+Doric.h"
|
||||||
|
#import "DoricSingleton.h"
|
||||||
|
|
||||||
@interface DoricDefaultMonitor : NSObject <DoricMonitorProtocol>
|
@interface DoricDefaultMonitor : NSObject <DoricMonitorProtocol>
|
||||||
@end
|
@end
|
||||||
@ -220,10 +221,20 @@ - (void)initDoricEnvironment {
|
|||||||
@try {
|
@try {
|
||||||
[self loadBuiltinJS:DORIC_BUNDLE_SANDBOX];
|
[self loadBuiltinJS:DORIC_BUNDLE_SANDBOX];
|
||||||
NSString *path;
|
NSString *path;
|
||||||
|
BOOL useLegacy;
|
||||||
if (@available(iOS 10.0, *)) {
|
if (@available(iOS 10.0, *)) {
|
||||||
path = [DoricBundle() pathForResource:DORIC_BUNDLE_LIB ofType:@"js"];
|
if (DoricSingleton.instance.legacyMode) {
|
||||||
|
useLegacy = YES;
|
||||||
} else {
|
} else {
|
||||||
|
useLegacy = NO;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
useLegacy = NO;
|
||||||
|
}
|
||||||
|
if (useLegacy) {
|
||||||
path = [DoricBundle() pathForResource:[NSString stringWithFormat:@"%@.es5", DORIC_BUNDLE_LIB] ofType:@"js"];
|
path = [DoricBundle() pathForResource:[NSString stringWithFormat:@"%@.es5", DORIC_BUNDLE_LIB] ofType:@"js"];
|
||||||
|
} else {
|
||||||
|
path = [DoricBundle() pathForResource:DORIC_BUNDLE_LIB ofType:@"js"];
|
||||||
}
|
}
|
||||||
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
||||||
[self.jsExecutor loadJSScript:[self packageModuleScript:DORIC_MODULE_LIB content:jsContent]
|
[self.jsExecutor loadJSScript:[self packageModuleScript:DORIC_MODULE_LIB content:jsContent]
|
||||||
@ -235,10 +246,20 @@ - (void)initDoricEnvironment {
|
|||||||
|
|
||||||
- (void)loadBuiltinJS:(NSString *)fileName {
|
- (void)loadBuiltinJS:(NSString *)fileName {
|
||||||
NSString *path;
|
NSString *path;
|
||||||
|
BOOL useLegacy;
|
||||||
if (@available(iOS 10.0, *)) {
|
if (@available(iOS 10.0, *)) {
|
||||||
path = [DoricBundle() pathForResource:DORIC_BUNDLE_SANDBOX ofType:@"js"];
|
if (DoricSingleton.instance.legacyMode) {
|
||||||
|
useLegacy = YES;
|
||||||
} else {
|
} else {
|
||||||
|
useLegacy = NO;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
useLegacy = NO;
|
||||||
|
}
|
||||||
|
if (useLegacy) {
|
||||||
path = [DoricBundle() pathForResource:[NSString stringWithFormat:@"%@.es5", DORIC_BUNDLE_SANDBOX] ofType:@"js"];
|
path = [DoricBundle() pathForResource:[NSString stringWithFormat:@"%@.es5", DORIC_BUNDLE_SANDBOX] ofType:@"js"];
|
||||||
|
} else {
|
||||||
|
path = [DoricBundle() pathForResource:DORIC_BUNDLE_SANDBOX ofType:@"js"];
|
||||||
}
|
}
|
||||||
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
||||||
[self.jsExecutor loadJSScript:jsContent source:[@"Assets://" stringByAppendingString:fileName]];
|
[self.jsExecutor loadJSScript:jsContent source:[@"Assets://" stringByAppendingString:fileName]];
|
||||||
|
@ -2725,6 +2725,10 @@ var Slider = /** @class */ (function (_super) {
|
|||||||
Property,
|
Property,
|
||||||
__metadata$9("design:type", Boolean)
|
__metadata$9("design:type", Boolean)
|
||||||
], Slider.prototype, "bounces", void 0);
|
], Slider.prototype, "bounces", void 0);
|
||||||
|
__decorate$9([
|
||||||
|
Property,
|
||||||
|
__metadata$9("design:type", String)
|
||||||
|
], Slider.prototype, "pageTransformer", void 0);
|
||||||
return Slider;
|
return Slider;
|
||||||
}(Superview));
|
}(Superview));
|
||||||
function slider(config) {
|
function slider(config) {
|
||||||
|
@ -2066,6 +2066,10 @@ __decorate$9([
|
|||||||
Property,
|
Property,
|
||||||
__metadata$9("design:type", Boolean)
|
__metadata$9("design:type", Boolean)
|
||||||
], Slider.prototype, "bounces", void 0);
|
], Slider.prototype, "bounces", void 0);
|
||||||
|
__decorate$9([
|
||||||
|
Property,
|
||||||
|
__metadata$9("design:type", String)
|
||||||
|
], Slider.prototype, "pageTransformer", void 0);
|
||||||
function slider(config) {
|
function slider(config) {
|
||||||
const ret = new Slider;
|
const ret = new Slider;
|
||||||
ret.apply(config);
|
ret.apply(config);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -3594,6 +3594,10 @@ __decorate$9([
|
|||||||
Property,
|
Property,
|
||||||
__metadata$9("design:type", Boolean)
|
__metadata$9("design:type", Boolean)
|
||||||
], Slider.prototype, "bounces", void 0);
|
], Slider.prototype, "bounces", void 0);
|
||||||
|
__decorate$9([
|
||||||
|
Property,
|
||||||
|
__metadata$9("design:type", String)
|
||||||
|
], Slider.prototype, "pageTransformer", void 0);
|
||||||
function slider(config) {
|
function slider(config) {
|
||||||
const ret = new Slider;
|
const ret = new Slider;
|
||||||
ret.apply(config);
|
ret.apply(config);
|
||||||
|
1
doric-js/index.d.ts
vendored
1
doric-js/index.d.ts
vendored
@ -810,6 +810,7 @@ declare module 'doric/lib/src/widget/slider' {
|
|||||||
* Take effect only on iOS
|
* Take effect only on iOS
|
||||||
*/
|
*/
|
||||||
bounces?: boolean;
|
bounces?: boolean;
|
||||||
|
pageTransformer?: "zoomout";
|
||||||
slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise<any>;
|
slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise<any>;
|
||||||
getSlidedPage(context: BridgeContext): Promise<number>;
|
getSlidedPage(context: BridgeContext): Promise<number>;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
import 'core-js';
|
||||||
class ProxyPolyfill {
|
class ProxyPolyfill {
|
||||||
__target__: object
|
__target__: object
|
||||||
__handler__: ProxyHandler<object>
|
__handler__: ProxyHandler<object>
|
||||||
@ -53,6 +54,4 @@ class ProxyPolyfill {
|
|||||||
}
|
}
|
||||||
const global = Function('return this')()
|
const global = Function('return this')()
|
||||||
global.Proxy = ProxyPolyfill
|
global.Proxy = ProxyPolyfill
|
||||||
|
|
||||||
export * from './src/runtime/sandbox.es5'
|
export * from './src/runtime/sandbox.es5'
|
||||||
export * from 'core-js'
|
|
||||||
|
1
doric-js/lib/src/widget/slider.d.ts
vendored
1
doric-js/lib/src/widget/slider.d.ts
vendored
@ -20,6 +20,7 @@ export declare class Slider extends Superview {
|
|||||||
* Take effect only on iOS
|
* Take effect only on iOS
|
||||||
*/
|
*/
|
||||||
bounces?: boolean;
|
bounces?: boolean;
|
||||||
|
pageTransformer?: "zoomout";
|
||||||
private getItem;
|
private getItem;
|
||||||
private renderBunchedItems;
|
private renderBunchedItems;
|
||||||
slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise<any>;
|
slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise<any>;
|
||||||
|
@ -88,6 +88,10 @@ __decorate([
|
|||||||
Property,
|
Property,
|
||||||
__metadata("design:type", Boolean)
|
__metadata("design:type", Boolean)
|
||||||
], Slider.prototype, "bounces", void 0);
|
], Slider.prototype, "bounces", void 0);
|
||||||
|
__decorate([
|
||||||
|
Property,
|
||||||
|
__metadata("design:type", String)
|
||||||
|
], Slider.prototype, "pageTransformer", void 0);
|
||||||
export function slider(config) {
|
export function slider(config) {
|
||||||
const ret = new Slider;
|
const ret = new Slider;
|
||||||
ret.apply(config);
|
ret.apply(config);
|
||||||
|
@ -30,14 +30,15 @@
|
|||||||
"registry": "https://registry.npmjs.org"
|
"registry": "https://registry.npmjs.org"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/ws": "^7.2.6",
|
|
||||||
"core-js": "^3.9.1",
|
|
||||||
"proxy-polyfill": "^0.3.2",
|
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rollup": "^2.40.0",
|
|
||||||
"dts-bundle": "^0.7.3",
|
|
||||||
"@rollup/plugin-buble": "^0.21.3",
|
"@rollup/plugin-buble": "^0.21.3",
|
||||||
"@rollup/plugin-commonjs": "^14.0.0",
|
"@rollup/plugin-commonjs": "^14.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^8.4.0"
|
"@rollup/plugin-node-resolve": "^8.4.0",
|
||||||
|
"@types/core-js": "^2.5.5",
|
||||||
|
"@types/ws": "^7.2.6",
|
||||||
|
"core-js": "^3.9.1",
|
||||||
|
"dts-bundle": "^0.7.3",
|
||||||
|
"proxy-polyfill": "^0.3.2",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rollup": "^2.40.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,9 @@ export class Slider extends Superview {
|
|||||||
@Property
|
@Property
|
||||||
bounces?: boolean
|
bounces?: boolean
|
||||||
|
|
||||||
|
@Property
|
||||||
|
pageTransformer?: "zoomout"
|
||||||
|
|
||||||
private getItem(itemIdx: number) {
|
private getItem(itemIdx: number) {
|
||||||
let view = this.renderPage(itemIdx)
|
let view = this.renderPage(itemIdx)
|
||||||
view.superview = this
|
view.superview = this
|
||||||
|
4
doric-web/dist/index.js
vendored
4
doric-web/dist/index.js
vendored
@ -3668,6 +3668,10 @@ __decorate$9([
|
|||||||
Property,
|
Property,
|
||||||
__metadata$9("design:type", Boolean)
|
__metadata$9("design:type", Boolean)
|
||||||
], Slider.prototype, "bounces", void 0);
|
], Slider.prototype, "bounces", void 0);
|
||||||
|
__decorate$9([
|
||||||
|
Property,
|
||||||
|
__metadata$9("design:type", String)
|
||||||
|
], Slider.prototype, "pageTransformer", void 0);
|
||||||
function slider(config) {
|
function slider(config) {
|
||||||
const ret = new Slider;
|
const ret = new Slider;
|
||||||
ret.apply(config);
|
ret.apply(config);
|
||||||
|
2
doric-web/dist/index.js.map
vendored
2
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user