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() {
|
||||
return DoricSingleton.getInstance().getJSLoaderManager();
|
||||
}
|
||||
|
||||
public static void setLegacyMode(boolean legacyMode) {
|
||||
DoricSingleton.getInstance().legacyMode = legacyMode;
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ public class DoricSingleton {
|
||||
boolean enableRenderSnapshot = false;
|
||||
private DoricNativeDriver nativeDriver;
|
||||
private final DoricContextManager doricContextManager = new DoricContextManager();
|
||||
public boolean legacyMode = false;
|
||||
|
||||
private static class Inner {
|
||||
private static final DoricSingleton sInstance = new DoricSingleton();
|
||||
|
@ -43,6 +43,7 @@ import pub.doric.Doric;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricContextManager;
|
||||
import pub.doric.DoricRegistry;
|
||||
import pub.doric.DoricSingleton;
|
||||
import pub.doric.IDoricMonitor;
|
||||
import pub.doric.extension.bridge.DoricBridgeExtension;
|
||||
import pub.doric.extension.timer.DoricTimerExtension;
|
||||
@ -109,14 +110,14 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
e.printStackTrace(new PrintWriter(stringWriter));
|
||||
mDoricRegistry.onLog(Log.ERROR, stringWriter.toString());
|
||||
//In case some unexpected errors happened
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
// mDoricRegistry.onLog(Log.WARN, "Use DoricWebViewJSExecutor");
|
||||
// mDoricJSE = new DoricWebViewJSExecutor(Doric.application());
|
||||
// loadBuiltinJS("doric-web.js");
|
||||
// } else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
mDoricRegistry.onLog(Log.WARN, "Use DoricWebViewJSExecutor");
|
||||
mDoricJSE = new DoricWebViewJSExecutor(Doric.application());
|
||||
loadBuiltinJS("doric-web.js");
|
||||
} else {
|
||||
mDoricRegistry.onLog(Log.WARN, "Use DoricWebShellJSExecutor");
|
||||
mDoricJSE = new DoricWebShellJSExecutor(Doric.application());
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,9 +261,10 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
|
||||
private void initDoricRuntime() {
|
||||
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 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);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException(null, e);
|
||||
|
@ -22,7 +22,9 @@ package pub.doric.utils;
|
||||
*/
|
||||
public class DoricConstant {
|
||||
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_ES5 = "doric-lib.es5.js";
|
||||
public static final String DORIC_MODULE_LIB = "doric";
|
||||
|
||||
|
||||
|
@ -61,4 +61,9 @@
|
||||
+ (void)setEnvironmentValue:(NSDictionary *)value;
|
||||
|
||||
+ (DoricJSLoaderManager *)jsLoaderManager;
|
||||
|
||||
/**
|
||||
* Set legacy mode to compat es5 code
|
||||
* */
|
||||
+ (void)setLegacyMode:(BOOL)legacy;
|
||||
@end
|
@ -55,4 +55,8 @@ + (void)setEnvironmentValue:(NSDictionary *)value {
|
||||
+ (DoricJSLoaderManager *)jsLoaderManager {
|
||||
return DoricSingleton.instance.jsLoaderManager;
|
||||
}
|
||||
|
||||
+ (void)setLegacyMode:(BOOL)legacy {
|
||||
[DoricSingleton.instance setLegacyMode:legacy];
|
||||
}
|
||||
@end
|
@ -32,6 +32,7 @@
|
||||
@property(nonatomic, strong) NSMutableDictionary *envDic;
|
||||
@property(nonatomic, assign) BOOL enablePerformance;
|
||||
@property(nonatomic, assign) BOOL enableRecordSnapshot;
|
||||
@property(nonatomic, assign) BOOL legacyMode;
|
||||
@property(nonatomic, strong) DoricJSLoaderManager *jsLoaderManager;
|
||||
@property(nonatomic, strong) DoricNativeDriver *nativeDriver;
|
||||
@property(nonatomic, strong) DoricContextManager *contextManager;
|
||||
|
@ -38,6 +38,7 @@ - (instancetype)init {
|
||||
valueOptions:NSPointerFunctionsWeakMemory
|
||||
capacity:0];
|
||||
_bundles = [NSMutableDictionary new];
|
||||
_legacyMode = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#import "DoricContextManager.h"
|
||||
#import "DoricPerformanceProfile.h"
|
||||
#import "JSValue+Doric.h"
|
||||
#import "DoricSingleton.h"
|
||||
|
||||
@interface DoricDefaultMonitor : NSObject <DoricMonitorProtocol>
|
||||
@end
|
||||
@ -220,10 +221,20 @@ - (void)initDoricEnvironment {
|
||||
@try {
|
||||
[self loadBuiltinJS:DORIC_BUNDLE_SANDBOX];
|
||||
NSString *path;
|
||||
BOOL useLegacy;
|
||||
if (@available(iOS 10.0, *)) {
|
||||
path = [DoricBundle() pathForResource:DORIC_BUNDLE_LIB ofType:@"js"];
|
||||
if (DoricSingleton.instance.legacyMode) {
|
||||
useLegacy = YES;
|
||||
} else {
|
||||
useLegacy = NO;
|
||||
}
|
||||
} else {
|
||||
useLegacy = NO;
|
||||
}
|
||||
if (useLegacy) {
|
||||
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];
|
||||
[self.jsExecutor loadJSScript:[self packageModuleScript:DORIC_MODULE_LIB content:jsContent]
|
||||
@ -235,10 +246,20 @@ - (void)initDoricEnvironment {
|
||||
|
||||
- (void)loadBuiltinJS:(NSString *)fileName {
|
||||
NSString *path;
|
||||
BOOL useLegacy;
|
||||
if (@available(iOS 10.0, *)) {
|
||||
path = [DoricBundle() pathForResource:DORIC_BUNDLE_SANDBOX ofType:@"js"];
|
||||
if (DoricSingleton.instance.legacyMode) {
|
||||
useLegacy = YES;
|
||||
} else {
|
||||
useLegacy = NO;
|
||||
}
|
||||
} else {
|
||||
useLegacy = NO;
|
||||
}
|
||||
if (useLegacy) {
|
||||
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];
|
||||
[self.jsExecutor loadJSScript:jsContent source:[@"Assets://" stringByAppendingString:fileName]];
|
||||
|
@ -2725,6 +2725,10 @@ var Slider = /** @class */ (function (_super) {
|
||||
Property,
|
||||
__metadata$9("design:type", Boolean)
|
||||
], Slider.prototype, "bounces", void 0);
|
||||
__decorate$9([
|
||||
Property,
|
||||
__metadata$9("design:type", String)
|
||||
], Slider.prototype, "pageTransformer", void 0);
|
||||
return Slider;
|
||||
}(Superview));
|
||||
function slider(config) {
|
||||
|
@ -2066,6 +2066,10 @@ __decorate$9([
|
||||
Property,
|
||||
__metadata$9("design:type", Boolean)
|
||||
], Slider.prototype, "bounces", void 0);
|
||||
__decorate$9([
|
||||
Property,
|
||||
__metadata$9("design:type", String)
|
||||
], Slider.prototype, "pageTransformer", void 0);
|
||||
function slider(config) {
|
||||
const ret = new Slider;
|
||||
ret.apply(config);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3594,6 +3594,10 @@ __decorate$9([
|
||||
Property,
|
||||
__metadata$9("design:type", Boolean)
|
||||
], Slider.prototype, "bounces", void 0);
|
||||
__decorate$9([
|
||||
Property,
|
||||
__metadata$9("design:type", String)
|
||||
], Slider.prototype, "pageTransformer", void 0);
|
||||
function slider(config) {
|
||||
const ret = new Slider;
|
||||
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
|
||||
*/
|
||||
bounces?: boolean;
|
||||
pageTransformer?: "zoomout";
|
||||
slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise<any>;
|
||||
getSlidedPage(context: BridgeContext): Promise<number>;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import 'core-js';
|
||||
class ProxyPolyfill {
|
||||
__target__: object
|
||||
__handler__: ProxyHandler<object>
|
||||
@ -53,6 +54,4 @@ class ProxyPolyfill {
|
||||
}
|
||||
const global = Function('return this')()
|
||||
global.Proxy = ProxyPolyfill
|
||||
|
||||
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
|
||||
*/
|
||||
bounces?: boolean;
|
||||
pageTransformer?: "zoomout";
|
||||
private getItem;
|
||||
private renderBunchedItems;
|
||||
slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise<any>;
|
||||
|
@ -88,6 +88,10 @@ __decorate([
|
||||
Property,
|
||||
__metadata("design:type", Boolean)
|
||||
], Slider.prototype, "bounces", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", String)
|
||||
], Slider.prototype, "pageTransformer", void 0);
|
||||
export function slider(config) {
|
||||
const ret = new Slider;
|
||||
ret.apply(config);
|
||||
|
@ -30,14 +30,15 @@
|
||||
"registry": "https://registry.npmjs.org"
|
||||
},
|
||||
"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-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
|
||||
bounces?: boolean
|
||||
|
||||
@Property
|
||||
pageTransformer?: "zoomout"
|
||||
|
||||
private getItem(itemIdx: number) {
|
||||
let view = this.renderPage(itemIdx)
|
||||
view.superview = this
|
||||
|
4
doric-web/dist/index.js
vendored
4
doric-web/dist/index.js
vendored
@ -3668,6 +3668,10 @@ __decorate$9([
|
||||
Property,
|
||||
__metadata$9("design:type", Boolean)
|
||||
], Slider.prototype, "bounces", void 0);
|
||||
__decorate$9([
|
||||
Property,
|
||||
__metadata$9("design:type", String)
|
||||
], Slider.prototype, "pageTransformer", void 0);
|
||||
function slider(config) {
|
||||
const ret = new Slider;
|
||||
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