feat:DoricPanelFragment use DoricJSLoader to load js bundle

This commit is contained in:
pengfei.zhou 2019-11-23 15:11:11 +08:00
parent e1ac85d18a
commit 920ca8d41e
5 changed files with 61 additions and 8 deletions

View File

@ -33,15 +33,18 @@ import androidx.fragment.app.Fragment;
public class DoricFragment extends Fragment {
private FrameLayout root;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
root = (FrameLayout) inflater.inflate(R.layout.doric_fragment, container, false);
return root;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
requireFragmentManager().beginTransaction()
.add(R.id.root, DoricPanelFragment.newInstance("assets://demo/Counter.js", "Counter.js"))
.commit();
}
}

View File

@ -16,6 +16,7 @@
package pub.doric;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -24,15 +25,59 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import pub.doric.async.AsyncResult;
import pub.doric.loader.DoricJSLoaderManager;
import pub.doric.utils.DoricLog;
/**
* @Description: pub.doric
* @Author: pengfei.zhou
* @CreateDate: 2019-11-23
*/
public class DoricPanelFragment extends Fragment {
@Nullable
private DoricPanel doricPanel;
public static DoricPanelFragment newInstance(String scheme, String alias) {
Bundle args = new Bundle();
args.putString("scheme", scheme);
args.putString("alias", alias);
DoricPanelFragment fragment = new DoricPanelFragment();
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
doricPanel = (DoricPanel) inflater.inflate(R.layout.doric_framgent_panel, container, false);
return doricPanel;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Bundle argument = getArguments();
if (argument == null) {
DoricLog.e("DoricPanelFragment argument is null");
return;
}
final String alias = argument.getString("alias");
String scheme = argument.getString("scheme");
DoricJSLoaderManager.getInstance().loadJSBundle(scheme).setCallback(new AsyncResult.Callback<String>() {
@Override
public void onResult(String result) {
doricPanel.config(result, alias);
}
@Override
public void onError(Throwable t) {
DoricLog.e("DoricPanelFragment load JS error:" + t.getLocalizedMessage());
}
@Override
public void onFinish() {
}
});
}
}

View File

@ -48,7 +48,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* @Description: com.github.penfeizhou.doric
* @Description: pub.doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-20
*/

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<pub.doric.DoricPanel xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />