feat:Navigator add extra

This commit is contained in:
pengfei.zhou 2019-12-09 20:33:36 +08:00
parent 3221b642c5
commit a4cd1c3c24
8 changed files with 39 additions and 30 deletions

View File

@ -40,7 +40,7 @@ public class DemoActivity extends AppCompatActivity {
DoricPanel doricPanel = new DoricPanel(this); DoricPanel doricPanel = new DoricPanel(this);
addContentView(doricPanel, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, addContentView(doricPanel, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
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(); doricContext = doricPanel.getDoricContext();
} }
} }

View File

@ -33,7 +33,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import pub.doric.DoricActivity;
import pub.doric.devkit.ui.DemoDebugActivity; import pub.doric.devkit.ui.DemoDebugActivity;
import pub.doric.refresh.DoricSwipeLayout; import pub.doric.refresh.DoricSwipeLayout;
import pub.doric.utils.DoricUtils; import pub.doric.utils.DoricUtils;
@ -63,7 +62,6 @@ public class MainActivity extends AppCompatActivity {
try { try {
String[] demos = getAssets().list("demo"); String[] demos = getAssets().list("demo");
List<String> ret = new ArrayList<>(); List<String> ret = new ArrayList<>();
ret.add("Test");
for (String str : demos) { for (String str : demos) {
if (str.endsWith("js")) { if (str.endsWith("js")) {
ret.add(str); ret.add(str);
@ -107,20 +105,9 @@ public class MainActivity extends AppCompatActivity {
tv.setOnClickListener(new View.OnClickListener() { tv.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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 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); tv.getContext().startActivity(intent);
} }
}); });

View File

@ -15,7 +15,6 @@
*/ */
package pub.doric; package pub.doric;
import android.animation.Animator;
import android.animation.AnimatorSet; import android.animation.AnimatorSet;
import android.content.Context; import android.content.Context;
@ -49,6 +48,7 @@ public class DoricContext {
private RootNode mRootNode = new RootNode(this); private RootNode mRootNode = new RootNode(this);
private final String source; private final String source;
private String script; private String script;
private String extra;
private JSONObject initParams; private JSONObject initParams;
private IDoricDriver doricDriver; private IDoricDriver doricDriver;
private final Map<String, ViewNode> mHeadNodes = new HashMap<>(); private final Map<String, ViewNode> mHeadNodes = new HashMap<>();
@ -72,10 +72,11 @@ public class DoricContext {
return mHeadNodes.get(id); 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.mContext = context;
this.mContextId = contextId; this.mContextId = contextId;
this.source = source; this.source = source;
this.extra = extra;
} }
public String getSource() { public String getSource() {
@ -86,17 +87,20 @@ public class DoricContext {
return script; return script;
} }
public static DoricContext create(Context context, String script, String source) { public static DoricContext create(Context context, String script, String source, String extra) {
DoricContext doricContext = DoricContextManager.getInstance().createContext(context, script, source); DoricContext doricContext = DoricContextManager.getInstance().createContext(context, script, source, extra);
doricContext.script = script; doricContext.script = script;
doricContext.extra = extra;
return doricContext; return doricContext;
} }
public void init(float width, float height) { public void init(float width, float height) {
this.initParams = new JSONBuilder() this.initParams = new JSONBuilder()
.put("width", width) .put("width", width)
.put("height", height).toJSONObject(); .put("height", height)
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams); .toJSONObject()
;
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams, extra);
callEntity(DoricConstant.DORIC_ENTITY_CREATE); callEntity(DoricConstant.DORIC_ENTITY_CREATE);
} }

View File

@ -48,9 +48,9 @@ public class DoricContextManager {
return Inner.sInstance; 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 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); doricContextMap.put(contextId, doricContext);
doricContext.getDriver().createContext(contextId, script, source); doricContext.getDriver().createContext(contextId, script, source);
return doricContext; return doricContext;

View File

@ -54,8 +54,8 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver {
} }
public void config(String script, String alias) { public void config(String script, String alias, String extra) {
DoricContext doricContext = DoricContext.create(getContext(), script, alias); DoricContext doricContext = DoricContext.create(getContext(), script, alias, extra);
config(doricContext); config(doricContext);
} }

View File

@ -62,10 +62,11 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator {
} }
final String alias = argument.getString("alias"); final String alias = argument.getString("alias");
String scheme = argument.getString("scheme"); String scheme = argument.getString("scheme");
final String extra = argument.getString("extra");
DoricJSLoaderManager.getInstance().loadJSBundle(scheme).setCallback(new AsyncResult.Callback<String>() { DoricJSLoaderManager.getInstance().loadJSBundle(scheme).setCallback(new AsyncResult.Callback<String>() {
@Override @Override
public void onResult(String result) { public void onResult(String result) {
doricPanel.config(result, alias); doricPanel.config(result, alias, extra);
DoricContext context = doricPanel.getDoricContext(); DoricContext context = doricPanel.getDoricContext();
context.setDoricNavigator(DoricPanelFragment.this); context.setDoricNavigator(DoricPanelFragment.this);
BaseDoricNavBar navBar = requireActivity().getWindow().getDecorView().findViewById(R.id.doric_nav_bar); BaseDoricNavBar navBar = requireActivity().getWindow().getDecorView().findViewById(R.id.doric_nav_bar);
@ -85,10 +86,11 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator {
} }
@Override @Override
public void push(String scheme, String alias) { public void push(String scheme, String alias, String extra) {
Bundle argument = new Bundle(); Bundle argument = new Bundle();
argument.putString("scheme", scheme); argument.putString("scheme", scheme);
argument.putString("alias", alias); argument.putString("alias", alias);
argument.putString("extra", extra);
getNavController() getNavController()
.navigate(R.id.action_doricPanelFragment_to_doricPanelFragment, argument); .navigate(R.id.action_doricPanelFragment_to_doricPanelFragment, argument);
} }

View File

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

View File

@ -18,6 +18,7 @@ package pub.doric.plugin;
import com.github.pengfeizhou.jscore.ArchiveException; import com.github.pengfeizhou.jscore.ArchiveException;
import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue;
import com.github.pengfeizhou.jscore.JavaValue; import com.github.pengfeizhou.jscore.JavaValue;
import pub.doric.Doric; import pub.doric.Doric;
@ -45,8 +46,23 @@ public class NavigatorPlugin extends DoricJavaPlugin {
if (navigator != null) { if (navigator != null) {
try { try {
JSObject jsObject = jsDecoder.decode().asObject(); 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(), navigator.push(jsObject.getProperty("scheme").asString().value(),
jsObject.getProperty("alias").asString().value() alias,
extra
); );
promise.resolve(); promise.resolve();
} catch (ArchiveException e) { } catch (ArchiveException e) {