refact:change field name from scheme to source

This commit is contained in:
pengfei.zhou 2020-02-17 21:23:02 +08:00 committed by osborn
parent 9e54ba1ea6
commit 0961cb9fc9
32 changed files with 72 additions and 91 deletions

View File

@ -106,7 +106,7 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
Intent intent = new Intent(tv.getContext(), DemoDebugActivity.class);
intent.putExtra("scheme", "assets://src/" + data[position]);
intent.putExtra("source", "assets://src/" + data[position]);
intent.putExtra("alias", data[position]);
tv.getContext().startActivity(intent);
}

View File

@ -33,7 +33,7 @@ public class DoricActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.doric_activity);
if (savedInstanceState == null) {
mDoricFragment = DoricFragment.newInstance(getScheme(), getAlias(), getExtra());
mDoricFragment = DoricFragment.newInstance(getSource(), getAlias(), getExtra());
getSupportFragmentManager().beginTransaction()
.add(R.id.container, mDoricFragment)
.commit();
@ -43,8 +43,8 @@ public class DoricActivity extends AppCompatActivity {
/**
* @return Scheme for DoricFragment to load.
*/
protected String getScheme() {
return getIntent().getStringExtra("scheme");
protected String getSource() {
return getIntent().getStringExtra("source");
}
/**

View File

@ -35,9 +35,9 @@ import androidx.navigation.Navigation;
*/
public class DoricFragment extends Fragment {
public static DoricFragment newInstance(String scheme, String alias, String extra) {
public static DoricFragment newInstance(String source, String alias, String extra) {
Bundle args = new Bundle();
args.putString("scheme", scheme);
args.putString("source", source);
args.putString("alias", alias);
args.putString("extra", extra);
DoricFragment fragment = new DoricFragment();

View File

@ -72,9 +72,9 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator {
}
@Override
public void push(String scheme, String alias, String extra) {
public void push(String source, String alias, String extra) {
Bundle argument = new Bundle();
argument.putString("scheme", scheme);
argument.putString("source", source);
argument.putString("alias", alias);
argument.putString("extra", extra);
getNavController()
@ -170,9 +170,9 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator {
}
showLoading();
final String alias = argument.getString("alias");
String scheme = argument.getString("scheme");
String source = argument.getString("source");
final String extra = argument.getString("extra");
DoricJSLoaderManager.getInstance().loadJSBundle(scheme).setCallback(new AsyncResult.Callback<String>() {
DoricJSLoaderManager.getInstance().loadJSBundle(source).setCallback(new AsyncResult.Callback<String>() {
@Override
public void onResult(String result) {
doricPanel.config(result, alias, extra);

View File

@ -30,14 +30,14 @@ import pub.doric.async.AsyncResult;
*/
public class DoricAssetJSLoader implements IDoricJSLoader {
@Override
public boolean filter(String scheme) {
return scheme.startsWith("assets");
public boolean filter(String source) {
return source.startsWith("assets");
}
@Override
public AsyncResult<String> request(String scheme) {
public AsyncResult<String> request(String source) {
AsyncResult<String> result = new AsyncResult<>();
String assetPath = scheme.substring("assets://".length());
String assetPath = source.substring("assets://".length());
InputStream inputStream = null;
try {
AssetManager assetManager = Doric.application().getAssets();

View File

@ -35,14 +35,14 @@ public class DoricHttpJSLoader implements IDoricJSLoader {
private OkHttpClient okHttpClient = new OkHttpClient();
@Override
public boolean filter(String scheme) {
return scheme.startsWith("http");
public boolean filter(String source) {
return source.startsWith("http");
}
@Override
public AsyncResult<String> request(String scheme) {
public AsyncResult<String> request(String source) {
final AsyncResult<String> ret = new AsyncResult<>();
okHttpClient.newCall(new Request.Builder().url(scheme).build()).enqueue(new Callback() {
okHttpClient.newCall(new Request.Builder().url(source).build()).enqueue(new Callback() {
@Override
public void onFailure(@NonNull Call call, @NonNull IOException e) {
ret.setError(e);

View File

@ -52,11 +52,11 @@ public class DoricJSLoaderManager {
return Inner.sInstance;
}
public AsyncResult<String> loadJSBundle(String scheme) {
public AsyncResult<String> loadJSBundle(String source) {
Collection<IDoricJSLoader> jsLoaders = getJSLoaders();
for (IDoricJSLoader jsLoader : jsLoaders) {
if (jsLoader.filter(scheme)) {
return jsLoader.request(scheme);
if (jsLoader.filter(source)) {
return jsLoader.request(source);
}
}
return new AsyncResult<>("");

View File

@ -23,7 +23,7 @@ import pub.doric.async.AsyncResult;
* @CreateDate: 2019-11-23
*/
public interface IDoricJSLoader {
boolean filter(String scheme);
boolean filter(String source);
AsyncResult<String> request(String scheme);
AsyncResult<String> request(String source);
}

View File

@ -21,7 +21,7 @@ package pub.doric.navigator;
* @CreateDate: 2019-11-23
*/
public interface IDoricNavigator {
void push(String scheme, String alias, String extra);
void push(String source, String alias, String extra);
void pop();
}

View File

@ -46,8 +46,8 @@ public class NavigatorPlugin extends DoricJavaPlugin {
if (navigator != null) {
try {
JSObject jsObject = jsDecoder.decode().asObject();
String scheme = jsObject.getProperty("scheme").asString().value();
String alias = scheme;
String source = jsObject.getProperty("source").asString().value();
String alias = source;
String extra = "";
JSValue config = jsObject.getProperty("config");
if (config.isObject()) {
@ -60,7 +60,7 @@ public class NavigatorPlugin extends DoricJavaPlugin {
extra = extraJS.asString().value();
}
}
navigator.push(jsObject.getProperty("scheme").asString().value(),
navigator.push(jsObject.getProperty("source").asString().value(),
alias,
extra
);

View File

@ -15,8 +15,8 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
String scheme = "assets://src/" + BUNDLE_NAME + ".js";
getIntent().putExtra("scheme", scheme);
String source = "assets://src/" + BUNDLE_NAME + ".js";
getIntent().putExtra("source", scheme);
getIntent().putExtra("alias", BUNDLE_NAME);
this.getSupportFragmentManager().beginTransaction().add(R.id.root, new DoricFragment()).commit();
}

View File

@ -17,7 +17,7 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *bundleName = @"__$__";
DoricViewController *doricViewController = [[DoricViewController alloc] initWithScheme:[NSString stringWithFormat:@"assets://src/%@.js", bundleName]
DoricViewController *doricViewController = [[DoricViewController alloc] initWithSource:[NSString stringWithFormat:@"assets://src/%@.js", bundleName]
alias:bundleName
extra:@""];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

View File

@ -8,7 +8,7 @@ @implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene *windowScene = (UIWindowScene *) scene;
NSString *bundleName = @"__$__";
DoricViewController *doricViewController = [[DoricViewController alloc] initWithScheme:[NSString stringWithFormat:@"assets://src/%@.js", bundleName]
DoricViewController *doricViewController = [[DoricViewController alloc] initWithSource:[NSString stringWithFormat:@"assets://src/%@.js", bundleName]
alias:bundleName
extra:@""];
doricViewController.view.backgroundColor = [UIColor whiteColor];

View File

@ -77,7 +77,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
DoricViewController *doricViewController = [[DoricViewController alloc]
initWithScheme:[NSString stringWithFormat:@"assets://src/%@", file]
initWithSource:[NSString stringWithFormat:@"assets://src/%@", file]
alias:self.demoFilePaths[(NSUInteger) indexPath.row]
extra:nil
];

View File

@ -32,5 +32,5 @@ extern NSString *const DORIC_MASK_RETRY;
@property(nonatomic, strong) UIView *loadingView;
@property(nonatomic, strong) UIView *errorView;
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias extra:(NSString *)extra;
- (instancetype)initWithSource:(NSString *)source alias:(NSString *)alias extra:(NSString *)extra;
@end

View File

@ -29,16 +29,16 @@ @interface DoricViewController ()
@property(nonatomic) BOOL navBarHidden;
@property(nonatomic, strong) UIImage *navBarImage;
@property(nonatomic, strong) UIView *maskView;
@property(nonatomic, copy) NSString *scheme;
@property(nonatomic, copy) NSString *source;
@property(nonatomic, copy) NSString *alias;
@property(nonatomic, copy) NSString *extra;
@end
@implementation DoricViewController
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias extra:(NSString *)extra {
- (instancetype)initWithSource:(NSString *)source alias:(NSString *)alias extra:(NSString *)extra {
if (self = [super init]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
_scheme = scheme;
_source = source;
_alias = alias;
_extra = extra;
_doricPanel = [DoricPanel new];
@ -105,8 +105,8 @@ - (void)viewWillLayoutSubviews {
self.doricPanel.view.height = self.view.height;
}
- (void)doric_navigator_push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra {
DoricViewController *viewController = [[DoricViewController alloc] initWithScheme:scheme alias:alias extra:extra];
- (void)doric_navigator_push:(NSString *)source alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra {
DoricViewController *viewController = [[DoricViewController alloc] initWithSource:source alias:alias extra:extra];
[self.navigationController pushViewController:viewController animated:animated];
}
@ -180,7 +180,7 @@ - (void)hideMask {
- (void)loadJSBundle {
[self showLoading];
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:self.scheme];
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:self.source];
result.resultCallback = ^(NSString *result) {
dispatch_async(dispatch_get_main_queue(), ^{
[self hideMask];

View File

@ -22,13 +22,13 @@
@implementation DoricHttpJSLoader
- (BOOL)filter:(NSString *)scheme {
return [scheme hasPrefix:@"http"];
- (BOOL)filter:(NSString *)source {
return [source hasPrefix:@"http"];
}
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme {
- (DoricAsyncResult <NSString *> *)request:(NSString *)source {
DoricAsyncResult *ret = [DoricAsyncResult new];
NSURL *URL = [NSURL URLWithString:scheme];
NSURL *URL = [NSURL URLWithString:source];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[[[NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]
dataTaskWithRequest:request

View File

@ -29,5 +29,5 @@
- (void)addJSLoader:(id <DoricLoaderProtocol>)loader;
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme;
- (DoricAsyncResult <NSString *> *)request:(NSString *)source;
@end

View File

@ -55,11 +55,11 @@ - (void)addJSLoader:(id <DoricLoaderProtocol>)loader {
}];
}
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme {
- (DoricAsyncResult <NSString *> *)request:(NSString *)source {
__block DoricAsyncResult *ret;
[self.loaders enumerateObjectsUsingBlock:^(id <DoricLoaderProtocol> obj, BOOL *stop) {
if ([obj filter:scheme]) {
ret = [obj request:scheme];
if ([obj filter:source]) {
ret = [obj request:source];
*stop = YES;
}
}];

View File

@ -21,7 +21,7 @@
#import "DoricAsyncResult.h"
@protocol DoricLoaderProtocol <NSObject>
- (BOOL)filter:(NSString *)scheme;
- (BOOL)filter:(NSString *)source;
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme;
- (DoricAsyncResult <NSString *> *)request:(NSString *)source;
@end

View File

@ -21,14 +21,14 @@
@implementation DoricMainBundleJSLoader
- (BOOL)filter:(NSString *)scheme {
return [scheme hasPrefix:@"assets"];
- (BOOL)filter:(NSString *)source {
return [source hasPrefix:@"assets"];
}
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme {
- (DoricAsyncResult <NSString *> *)request:(NSString *)source {
DoricAsyncResult <NSString *> *ret = [DoricAsyncResult new];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *fullPath = [path stringByAppendingPathComponent:[scheme substringFromIndex:@"assets://".length]];
NSString *fullPath = [path stringByAppendingPathComponent:[source substringFromIndex:@"assets://".length]];
NSError *error;
NSString *jsContent = [NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:&error];
if (error) {

View File

@ -20,7 +20,7 @@
#import <Foundation/Foundation.h>
@protocol DoricNavigatorDelegate <NSObject>
- (void)doric_navigator_push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra;
- (void)doric_navigator_push:(NSString *)source alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra;
- (void)doric_navigator_pop:(BOOL)animated;
@end

View File

@ -24,8 +24,8 @@ @implementation DoricNavigatorPlugin
- (void)push:(NSDictionary *)params {
dispatch_async(dispatch_get_main_queue(), ^{
BOOL animated = YES;
NSString *scheme = params[@"scheme"];
NSString *alias = scheme;
NSString *source = params[@"source"];
NSString *alias = source;
NSDictionary *config = params[@"config"];
if (config) {
if (config[@"animated"]) {
@ -36,7 +36,7 @@ - (void)push:(NSDictionary *)params {
alias = config[@"alias"];
}
}
[self.doricContext.navigator doric_navigator_push:scheme alias:alias animated:animated extra:config[@"extra"]];
[self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]];
});
}

View File

@ -463,22 +463,3 @@ - (void)layoutSelf:(CGSize)targetSize {
}
}
@end
DoricVLayoutView *vLayout(NSArray <__kindof UIView *> *views) {
DoricVLayoutView *layout = [[DoricVLayoutView alloc] initWithFrame:CGRectZero];
for (__kindof UIView *uiView in views) {
[layout addSubview:uiView];
}
layout.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutWrapContent height:DoricLayoutWrapContent];
return layout;
}
DoricHLayoutView *hLayout(NSArray <__kindof UIView *> *views) {
DoricHLayoutView *layout = [[DoricHLayoutView alloc] initWithFrame:CGRectZero];
for (__kindof UIView *uiView in views) {
[layout addSubview:uiView];
}
layout.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutWrapContent height:DoricLayoutWrapContent];
return layout;
}

View File

@ -2504,12 +2504,12 @@ function navbar(context) {
function navigator(context) {
return {
push: function (scheme, config) {
push: function (source, config) {
if (config && config.extra) {
config.extra = JSON.stringify(config.extra);
}
return context.callNative('navigator', 'push', {
scheme: scheme, config: config
source: source, config: config
});
},
pop: function (animated) {

View File

@ -1879,12 +1879,12 @@ function navbar(context) {
function navigator(context) {
return {
push: (scheme, config) => {
push: (source, config) => {
if (config && config.extra) {
config.extra = JSON.stringify(config.extra);
}
return context.callNative('navigator', 'push', {
scheme, config
source, config
});
},
pop: (animated = true) => {

View File

@ -3338,12 +3338,12 @@ function navbar(context) {
function navigator(context) {
return {
push: (scheme, config) => {
push: (source, config) => {
if (config && config.extra) {
config.extra = JSON.stringify(config.extra);
}
return context.callNative('navigator', 'push', {
scheme, config
source, config
});
},
pop: (animated = true) => {

2
doric-js/index.d.ts vendored
View File

@ -754,7 +754,7 @@ declare module 'doric/lib/src/native/navbar' {
declare module 'doric/lib/src/native/navigator' {
import { BridgeContext } from "doric/lib/src/runtime/global";
export function navigator(context: BridgeContext): {
push: (scheme: string, config?: {
push: (source: string, config?: {
alias?: string | undefined;
animated?: boolean | undefined;
extra?: object | undefined;

View File

@ -1,6 +1,6 @@
import { BridgeContext } from "../runtime/global";
export declare function navigator(context: BridgeContext): {
push: (scheme: string, config?: {
push: (source: string, config?: {
alias?: string | undefined;
animated?: boolean | undefined;
extra?: object | undefined;

View File

@ -1,11 +1,11 @@
export function navigator(context) {
return {
push: (scheme, config) => {
push: (source, config) => {
if (config && config.extra) {
config.extra = JSON.stringify(config.extra);
}
return context.callNative('navigator', 'push', {
scheme, config
source, config
});
},
pop: (animated = true) => {

View File

@ -17,7 +17,7 @@ import { BridgeContext } from "../runtime/global"
export function navigator(context: BridgeContext) {
return {
push: (scheme: string, config?: {
push: (source: string, config?: {
alias?: string,
animated?: boolean,
extra?: object,
@ -26,7 +26,7 @@ export function navigator(context: BridgeContext) {
(config as any).extra = JSON.stringify(config.extra)
}
return context.callNative('navigator', 'push', {
scheme, config
source, config
})
},
pop: (animated = true) => {

View File

@ -6,7 +6,7 @@ export class NavigatorPlugin extends DoricPlugin {
navigation: NavigationElement | undefined = document.getElementsByTagName('doric-navigation')[0] as (NavigationElement | undefined)
push(args: {
scheme: string,
source: string,
config?: {
alias?: string,
extra?: string,
@ -14,8 +14,8 @@ export class NavigatorPlugin extends DoricPlugin {
}) {
if (this.navigation) {
const div = new DoricElement
div.src = args.scheme
div.alias = args.config?.alias || args.scheme
div.src = args.source
div.alias = args.config?.alias || args.source
this.navigation.push(div)
return Promise.resolve()
} else {