feat:Navigator add extra
This commit is contained in:
parent
3221b642c5
commit
a4cd1c3c24
@ -40,7 +40,7 @@ public class DemoActivity extends AppCompatActivity {
|
||||
DoricPanel doricPanel = new DoricPanel(this);
|
||||
addContentView(doricPanel, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
doricPanel.config(DoricUtils.readAssetFile("demo/" + source), source);
|
||||
doricPanel.config(DoricUtils.readAssetFile("demo/" + source), source, "");
|
||||
doricContext = doricPanel.getDoricContext();
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pub.doric.DoricActivity;
|
||||
import pub.doric.devkit.ui.DemoDebugActivity;
|
||||
import pub.doric.refresh.DoricSwipeLayout;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
@ -63,7 +62,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
try {
|
||||
String[] demos = getAssets().list("demo");
|
||||
List<String> ret = new ArrayList<>();
|
||||
ret.add("Test");
|
||||
for (String str : demos) {
|
||||
if (str.endsWith("js")) {
|
||||
ret.add(str);
|
||||
@ -107,20 +105,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
tv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (data[position].contains("Test")) {
|
||||
Intent intent = new Intent(tv.getContext(), PullableActivity.class);
|
||||
tv.getContext().startActivity(intent);
|
||||
return;
|
||||
}
|
||||
if (data[position].contains("NavigatorDemo")) {
|
||||
Intent intent = new Intent(tv.getContext(), DoricActivity.class);
|
||||
intent.putExtra("scheme", "assets://demo/" + data[position]);
|
||||
intent.putExtra("alias", data[position]);
|
||||
tv.getContext().startActivity(intent);
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent(tv.getContext(), DemoDebugActivity.class);
|
||||
intent.putExtra("source", data[position]);
|
||||
intent.putExtra("scheme", "assets://demo/" + data[position]);
|
||||
intent.putExtra("alias", data[position]);
|
||||
tv.getContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package pub.doric;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.content.Context;
|
||||
|
||||
@ -49,6 +48,7 @@ public class DoricContext {
|
||||
private RootNode mRootNode = new RootNode(this);
|
||||
private final String source;
|
||||
private String script;
|
||||
private String extra;
|
||||
private JSONObject initParams;
|
||||
private IDoricDriver doricDriver;
|
||||
private final Map<String, ViewNode> mHeadNodes = new HashMap<>();
|
||||
@ -72,10 +72,11 @@ public class DoricContext {
|
||||
return mHeadNodes.get(id);
|
||||
}
|
||||
|
||||
protected DoricContext(Context context, String contextId, String source) {
|
||||
protected DoricContext(Context context, String contextId, String source, String extra) {
|
||||
this.mContext = context;
|
||||
this.mContextId = contextId;
|
||||
this.source = source;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
@ -86,17 +87,20 @@ public class DoricContext {
|
||||
return script;
|
||||
}
|
||||
|
||||
public static DoricContext create(Context context, String script, String source) {
|
||||
DoricContext doricContext = DoricContextManager.getInstance().createContext(context, script, source);
|
||||
public static DoricContext create(Context context, String script, String source, String extra) {
|
||||
DoricContext doricContext = DoricContextManager.getInstance().createContext(context, script, source, extra);
|
||||
doricContext.script = script;
|
||||
doricContext.extra = extra;
|
||||
return doricContext;
|
||||
}
|
||||
|
||||
public void init(float width, float height) {
|
||||
this.initParams = new JSONBuilder()
|
||||
.put("width", width)
|
||||
.put("height", height).toJSONObject();
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams);
|
||||
.put("height", height)
|
||||
.toJSONObject()
|
||||
;
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams, extra);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,9 @@ public class DoricContextManager {
|
||||
return Inner.sInstance;
|
||||
}
|
||||
|
||||
DoricContext createContext(Context context, final String script, final String source) {
|
||||
DoricContext createContext(Context context, final String script, final String source, String extra) {
|
||||
final String contextId = String.valueOf(counter.incrementAndGet());
|
||||
final DoricContext doricContext = new DoricContext(context, contextId, source);
|
||||
final DoricContext doricContext = new DoricContext(context, contextId, source, extra);
|
||||
doricContextMap.put(contextId, doricContext);
|
||||
doricContext.getDriver().createContext(contextId, script, source);
|
||||
return doricContext;
|
||||
|
@ -54,8 +54,8 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver {
|
||||
}
|
||||
|
||||
|
||||
public void config(String script, String alias) {
|
||||
DoricContext doricContext = DoricContext.create(getContext(), script, alias);
|
||||
public void config(String script, String alias, String extra) {
|
||||
DoricContext doricContext = DoricContext.create(getContext(), script, alias, extra);
|
||||
config(doricContext);
|
||||
}
|
||||
|
||||
|
@ -62,10 +62,11 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator {
|
||||
}
|
||||
final String alias = argument.getString("alias");
|
||||
String scheme = argument.getString("scheme");
|
||||
final String extra = argument.getString("extra");
|
||||
DoricJSLoaderManager.getInstance().loadJSBundle(scheme).setCallback(new AsyncResult.Callback<String>() {
|
||||
@Override
|
||||
public void onResult(String result) {
|
||||
doricPanel.config(result, alias);
|
||||
doricPanel.config(result, alias, extra);
|
||||
DoricContext context = doricPanel.getDoricContext();
|
||||
context.setDoricNavigator(DoricPanelFragment.this);
|
||||
BaseDoricNavBar navBar = requireActivity().getWindow().getDecorView().findViewById(R.id.doric_nav_bar);
|
||||
@ -85,10 +86,11 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push(String scheme, String alias) {
|
||||
public void push(String scheme, String alias, String extra) {
|
||||
Bundle argument = new Bundle();
|
||||
argument.putString("scheme", scheme);
|
||||
argument.putString("alias", alias);
|
||||
argument.putString("extra", extra);
|
||||
getNavController()
|
||||
.navigate(R.id.action_doricPanelFragment_to_doricPanelFragment, argument);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ package pub.doric.navigator;
|
||||
* @CreateDate: 2019-11-23
|
||||
*/
|
||||
public interface IDoricNavigator {
|
||||
void push(String scheme, String alias);
|
||||
void push(String scheme, String alias, String extra);
|
||||
|
||||
void pop();
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package pub.doric.plugin;
|
||||
import com.github.pengfeizhou.jscore.ArchiveException;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import pub.doric.Doric;
|
||||
@ -45,8 +46,23 @@ 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 extra = "";
|
||||
JSValue config = jsObject.getProperty("config");
|
||||
if (config.isObject()) {
|
||||
JSValue aliasJS = config.asObject().getProperty("alias");
|
||||
if (aliasJS.isString()) {
|
||||
alias = aliasJS.asString().value();
|
||||
}
|
||||
JSValue extraJS = config.asObject().getProperty("extra");
|
||||
if (extraJS.isString()) {
|
||||
extra = extraJS.asString().value();
|
||||
}
|
||||
}
|
||||
navigator.push(jsObject.getProperty("scheme").asString().value(),
|
||||
jsObject.getProperty("alias").asString().value()
|
||||
alias,
|
||||
extra
|
||||
);
|
||||
promise.resolve();
|
||||
} catch (ArchiveException e) {
|
||||
|
Reference in New Issue
Block a user