Merge branch 'feature/slider' into 'master'
Feature/slider See merge request !25
This commit is contained in:
commit
f93e715db1
@ -18,7 +18,6 @@ package pub.doric.demo;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@ -30,6 +29,7 @@ import org.greenrobot.eventbus.ThreadMode;
|
|||||||
|
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
import pub.doric.DoricContextManager;
|
import pub.doric.DoricContextManager;
|
||||||
|
import pub.doric.DoricPanel;
|
||||||
import pub.doric.devkit.DoricContextDebuggable;
|
import pub.doric.devkit.DoricContextDebuggable;
|
||||||
import pub.doric.devkit.event.EnterDebugEvent;
|
import pub.doric.devkit.event.EnterDebugEvent;
|
||||||
import pub.doric.devkit.event.QuitDebugEvent;
|
import pub.doric.devkit.event.QuitDebugEvent;
|
||||||
@ -52,14 +52,12 @@ public class DemoActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
String source = getIntent().getStringExtra("source");
|
String source = getIntent().getStringExtra("source");
|
||||||
FrameLayout frameLayout = new FrameLayout(this);
|
DoricPanel doricPanel = new DoricPanel(this);
|
||||||
addContentView(frameLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
addContentView(doricPanel, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/" + source), source);
|
doricPanel.config(DoricUtils.readAssetFile("demo/" + source), source);
|
||||||
|
doricContext = doricPanel.getDoricContext();
|
||||||
doricContextDebuggable = new DoricContextDebuggable(doricContext);
|
doricContextDebuggable = new DoricContextDebuggable(doricContext);
|
||||||
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
||||||
doricContext.getRootNode().setRootView(frameLayout);
|
|
||||||
|
|
||||||
sensorHelper = new SensorManagerHelper(this);
|
sensorHelper = new SensorManagerHelper(this);
|
||||||
sensorHelper.setOnShakeListener(new SensorManagerHelper.OnShakeListener() {
|
sensorHelper.setOnShakeListener(new SensorManagerHelper.OnShakeListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -73,18 +71,6 @@ public class DemoActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
doricContext.onShow();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
doricContext.onHidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachedToWindow() {
|
public void onAttachedToWindow() {
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
@ -95,7 +81,6 @@ public class DemoActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
doricContext.teardown();
|
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
sensorHelper.stop();
|
sensorHelper.stop();
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ 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.utils.DoricUtils;
|
import pub.doric.utils.DoricUtils;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
@ -89,6 +90,13 @@ 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("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(), DemoActivity.class);
|
Intent intent = new Intent(tv.getContext(), DemoActivity.class);
|
||||||
intent.putExtra("source", data[position]);
|
intent.putExtra("source", data[position]);
|
||||||
tv.getContext().startActivity(intent);
|
tv.getContext().startActivity(intent);
|
||||||
|
@ -1 +1,16 @@
|
|||||||
<manifest package="pub.doric" />
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="pub.doric">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<activity android:name="pub.doric.DoricActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
|
53
Android/doric/src/main/java/pub/doric/DoricActivity.java
Normal file
53
Android/doric/src/main/java/pub/doric/DoricActivity.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package pub.doric;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: pub.doric.demo
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-19
|
||||||
|
*/
|
||||||
|
public class DoricActivity extends AppCompatActivity {
|
||||||
|
private DoricFragment doricFragment;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.doric_activity);
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
String scheme = getIntent().getStringExtra("scheme");
|
||||||
|
String alias = getIntent().getStringExtra("alias");
|
||||||
|
doricFragment = DoricFragment.newInstance(scheme, alias);
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.add(R.id.container, doricFragment)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
if (doricFragment.canPop()) {
|
||||||
|
doricFragment.pop();
|
||||||
|
} else {
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import pub.doric.async.AsyncResult;
|
import pub.doric.async.AsyncResult;
|
||||||
|
import pub.doric.navigator.IDoricNavigator;
|
||||||
import pub.doric.plugin.DoricJavaPlugin;
|
import pub.doric.plugin.DoricJavaPlugin;
|
||||||
import pub.doric.shader.RootNode;
|
import pub.doric.shader.RootNode;
|
||||||
import pub.doric.utils.DoricConstant;
|
import pub.doric.utils.DoricConstant;
|
||||||
@ -66,7 +67,7 @@ public class DoricContext {
|
|||||||
return doricContext;
|
return doricContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(int width, int 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).toJSONObject();
|
||||||
@ -148,4 +149,14 @@ public class DoricContext {
|
|||||||
public void onHidden() {
|
public void onHidden() {
|
||||||
callEntity(DoricConstant.DORIC_ENTITY_HIDDEN);
|
callEntity(DoricConstant.DORIC_ENTITY_HIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IDoricNavigator doricNavigator;
|
||||||
|
|
||||||
|
public void setDoricNavigator(IDoricNavigator doricNavigator) {
|
||||||
|
this.doricNavigator = doricNavigator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDoricNavigator getDoricNavigator() {
|
||||||
|
return this.doricNavigator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
84
Android/doric/src/main/java/pub/doric/DoricFragment.java
Normal file
84
Android/doric/src/main/java/pub/doric/DoricFragment.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package pub.doric;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import pub.doric.navigator.IDoricNavigator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: pub.doric
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-23
|
||||||
|
*/
|
||||||
|
public class DoricFragment extends Fragment implements IDoricNavigator {
|
||||||
|
|
||||||
|
public static DoricFragment newInstance(String scheme, String alias) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putString("scheme", scheme);
|
||||||
|
args.putString("alias", alias);
|
||||||
|
DoricFragment fragment = new DoricFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
return inflater.inflate(R.layout.doric_fragment, container, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
Bundle argument = getArguments();
|
||||||
|
if (argument != null) {
|
||||||
|
String alias = argument.getString("alias");
|
||||||
|
String scheme = argument.getString("scheme");
|
||||||
|
push(scheme, alias);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void push(String scheme, String alias) {
|
||||||
|
getChildFragmentManager().beginTransaction()
|
||||||
|
.add(R.id.root, DoricPanelFragment.newInstance(scheme, alias))
|
||||||
|
.addToBackStack(scheme)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pop() {
|
||||||
|
if (canPop()) {
|
||||||
|
getChildFragmentManager().popBackStack();
|
||||||
|
} else {
|
||||||
|
if (getActivity() != null) {
|
||||||
|
getActivity().finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canPop() {
|
||||||
|
return getChildFragmentManager().getBackStackEntryCount() > 1;
|
||||||
|
}
|
||||||
|
}
|
@ -16,40 +16,43 @@
|
|||||||
package pub.doric;
|
package pub.doric;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import pub.doric.utils.DoricUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: Doric
|
* @Description: Doric
|
||||||
* @Author: pengfei.zhou
|
* @Author: pengfei.zhou
|
||||||
* @CreateDate: 2019-07-18
|
* @CreateDate: 2019-07-18
|
||||||
*/
|
*/
|
||||||
public class DoricPanel extends FrameLayout {
|
public class DoricPanel extends FrameLayout implements LifecycleObserver {
|
||||||
|
|
||||||
private DoricContext mDoricContext;
|
private DoricContext mDoricContext;
|
||||||
|
|
||||||
public DoricPanel(@NonNull Context context) {
|
public DoricPanel(@NonNull Context context) {
|
||||||
super(context);
|
this(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs) {
|
public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||||
super(context, attrs);
|
this(context, attrs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
|
if (getContext() instanceof LifecycleOwner) {
|
||||||
|
((LifecycleOwner) getContext()).getLifecycle().addObserver(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void config(String script, String alias) {
|
public void config(String script, String alias) {
|
||||||
DoricContext doricContext = DoricContext.create(getContext(), script, alias);
|
DoricContext doricContext = DoricContext.create(getContext(), script, alias);
|
||||||
@ -58,6 +61,14 @@ public class DoricPanel extends FrameLayout {
|
|||||||
|
|
||||||
public void config(DoricContext doricContext) {
|
public void config(DoricContext doricContext) {
|
||||||
mDoricContext = doricContext;
|
mDoricContext = doricContext;
|
||||||
|
mDoricContext.getRootNode().setRootView(this);
|
||||||
|
if (getMeasuredState() != 0) {
|
||||||
|
mDoricContext.init(DoricUtils.px2dp(getMeasuredWidth()), DoricUtils.px2dp(getMeasuredHeight()));
|
||||||
|
}
|
||||||
|
if (getContext() instanceof LifecycleOwner
|
||||||
|
&& ((LifecycleOwner) getContext()).getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
||||||
|
mDoricContext.onShow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,4 +79,35 @@ public class DoricPanel extends FrameLayout {
|
|||||||
public DoricContext getDoricContext() {
|
public DoricContext getDoricContext() {
|
||||||
return mDoricContext;
|
return mDoricContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
|
if (oldw != w || oldh != h) {
|
||||||
|
if (mDoricContext != null) {
|
||||||
|
mDoricContext.init(DoricUtils.px2dp(w), DoricUtils.px2dp(h));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
|
public void onActivityResume() {
|
||||||
|
if (mDoricContext != null) {
|
||||||
|
mDoricContext.onShow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||||
|
public void onActivityPause() {
|
||||||
|
if (mDoricContext != null) {
|
||||||
|
mDoricContext.onHidden();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||||
|
public void onActivityDestroy() {
|
||||||
|
if (mDoricContext != null) {
|
||||||
|
mDoricContext.teardown();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package pub.doric;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
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.navigator.IDoricNavigator;
|
||||||
|
import pub.doric.utils.DoricLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: pub.doric
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-23
|
||||||
|
*/
|
||||||
|
public class DoricPanelFragment extends Fragment {
|
||||||
|
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) {
|
||||||
|
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);
|
||||||
|
DoricContext context = doricPanel.getDoricContext();
|
||||||
|
Fragment fragment = getParentFragment();
|
||||||
|
if (fragment instanceof IDoricNavigator) {
|
||||||
|
context.setDoricNavigator((IDoricNavigator) fragment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable t) {
|
||||||
|
DoricLog.e("DoricPanelFragment load JS error:" + t.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,10 @@ package pub.doric;
|
|||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import pub.doric.loader.DoricAssetJSLoader;
|
||||||
|
import pub.doric.loader.DoricHttpJSLoader;
|
||||||
|
import pub.doric.loader.IDoricJSLoader;
|
||||||
|
import pub.doric.plugin.NavigatorPlugin;
|
||||||
import pub.doric.plugin.NetworkPlugin;
|
import pub.doric.plugin.NetworkPlugin;
|
||||||
import pub.doric.plugin.ShaderPlugin;
|
import pub.doric.plugin.ShaderPlugin;
|
||||||
import pub.doric.plugin.StoragePlugin;
|
import pub.doric.plugin.StoragePlugin;
|
||||||
@ -36,6 +40,7 @@ import pub.doric.utils.DoricMetaInfo;
|
|||||||
import pub.doric.plugin.DoricJavaPlugin;
|
import pub.doric.plugin.DoricJavaPlugin;
|
||||||
import pub.doric.plugin.ModalPlugin;
|
import pub.doric.plugin.ModalPlugin;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -43,15 +48,22 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: com.github.penfeizhou.doric
|
* @Description: pub.doric
|
||||||
* @Author: pengfei.zhou
|
* @Author: pengfei.zhou
|
||||||
* @CreateDate: 2019-07-20
|
* @CreateDate: 2019-07-20
|
||||||
*/
|
*/
|
||||||
public class DoricRegistry {
|
public class DoricRegistry {
|
||||||
private static Map<String, String> bundles = new ConcurrentHashMap<>();
|
private static Map<String, String> bundles = new ConcurrentHashMap<>();
|
||||||
|
private static Set<DoricLibrary> doricLibraries = new HashSet<>();
|
||||||
|
private static Set<IDoricJSLoader> jsLoaders = new HashSet<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
addJSLoader(new DoricAssetJSLoader());
|
||||||
|
addJSLoader(new DoricHttpJSLoader());
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, DoricMetaInfo<DoricJavaPlugin>> pluginInfoMap = new HashMap<>();
|
private Map<String, DoricMetaInfo<DoricJavaPlugin>> pluginInfoMap = new HashMap<>();
|
||||||
private Map<String, DoricMetaInfo<ViewNode>> nodeInfoMap = new HashMap<>();
|
private Map<String, DoricMetaInfo<ViewNode>> nodeInfoMap = new HashMap<>();
|
||||||
private static Set<DoricLibrary> doricLibraries = new HashSet<>();
|
|
||||||
|
|
||||||
private static void initRegistry(DoricRegistry doricRegistry) {
|
private static void initRegistry(DoricRegistry doricRegistry) {
|
||||||
for (DoricLibrary library : doricLibraries) {
|
for (DoricLibrary library : doricLibraries) {
|
||||||
@ -69,6 +81,7 @@ public class DoricRegistry {
|
|||||||
this.registerNativePlugin(ModalPlugin.class);
|
this.registerNativePlugin(ModalPlugin.class);
|
||||||
this.registerNativePlugin(NetworkPlugin.class);
|
this.registerNativePlugin(NetworkPlugin.class);
|
||||||
this.registerNativePlugin(StoragePlugin.class);
|
this.registerNativePlugin(StoragePlugin.class);
|
||||||
|
this.registerNativePlugin(NavigatorPlugin.class);
|
||||||
this.registerViewNode(RootNode.class);
|
this.registerViewNode(RootNode.class);
|
||||||
this.registerViewNode(TextNode.class);
|
this.registerViewNode(TextNode.class);
|
||||||
this.registerViewNode(ImageNode.class);
|
this.registerViewNode(ImageNode.class);
|
||||||
@ -112,4 +125,12 @@ public class DoricRegistry {
|
|||||||
public String acquireJSBundle(String name) {
|
public String acquireJSBundle(String name) {
|
||||||
return bundles.get(name);
|
return bundles.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addJSLoader(IDoricJSLoader jsLoader) {
|
||||||
|
jsLoaders.add(jsLoader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<IDoricJSLoader> getJSLoaders() {
|
||||||
|
return jsLoaders;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,13 @@ public class AsyncResult<R> {
|
|||||||
|
|
||||||
private Callback<R> callback = null;
|
private Callback<R> callback = null;
|
||||||
|
|
||||||
|
public AsyncResult() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AsyncResult(R r) {
|
||||||
|
this.result = r;
|
||||||
|
}
|
||||||
|
|
||||||
public void setResult(R result) {
|
public void setResult(R result) {
|
||||||
this.result = result;
|
this.result = result;
|
||||||
if (this.callback != null) {
|
if (this.callback != null) {
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package pub.doric.loader;
|
||||||
|
|
||||||
|
import pub.doric.async.AsyncResult;
|
||||||
|
import pub.doric.utils.DoricUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: handle "assets://asset-file-path"
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-23
|
||||||
|
*/
|
||||||
|
public class DoricAssetJSLoader implements IDoricJSLoader {
|
||||||
|
@Override
|
||||||
|
public boolean filter(String scheme) {
|
||||||
|
return scheme.startsWith("assets");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AsyncResult<String> request(String scheme) {
|
||||||
|
return new AsyncResult<>(DoricUtils.readAssetFile(scheme.substring("assets://".length())));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package pub.doric.loader;
|
||||||
|
|
||||||
|
import com.bumptech.glide.RequestBuilder;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.Callback;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import pub.doric.async.AsyncResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: handle like "https://xxxx.js"
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-23
|
||||||
|
*/
|
||||||
|
public class DoricHttpJSLoader implements IDoricJSLoader {
|
||||||
|
private OkHttpClient okHttpClient = new OkHttpClient();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean filter(String scheme) {
|
||||||
|
return scheme.startsWith("http");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AsyncResult<String> request(String scheme) {
|
||||||
|
final AsyncResult<String> ret = new AsyncResult<>();
|
||||||
|
okHttpClient.newCall(new Request.Builder().url(scheme).build()).enqueue(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||||
|
ret.setError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NotNull Call call, @NotNull Response response) {
|
||||||
|
try {
|
||||||
|
ret.setResult(response.body().string());
|
||||||
|
} catch (Exception e) {
|
||||||
|
ret.setError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package pub.doric.loader;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import pub.doric.DoricRegistry;
|
||||||
|
import pub.doric.async.AsyncResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: pub.doric
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-23
|
||||||
|
*/
|
||||||
|
public class DoricJSLoaderManager {
|
||||||
|
private DoricJSLoaderManager() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Inner {
|
||||||
|
private static final DoricJSLoaderManager sInstance = new DoricJSLoaderManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DoricJSLoaderManager getInstance() {
|
||||||
|
return Inner.sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AsyncResult<String> loadJSBundle(String scheme) {
|
||||||
|
Collection<IDoricJSLoader> jsLoaders = DoricRegistry.getJSLoaders();
|
||||||
|
for (IDoricJSLoader jsLoader : jsLoaders) {
|
||||||
|
if (jsLoader.filter(scheme)) {
|
||||||
|
return jsLoader.request(scheme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new AsyncResult<>("");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package pub.doric.loader;
|
||||||
|
|
||||||
|
import pub.doric.async.AsyncResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: pub.doric
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-23
|
||||||
|
*/
|
||||||
|
public interface IDoricJSLoader {
|
||||||
|
boolean filter(String scheme);
|
||||||
|
|
||||||
|
AsyncResult<String> request(String scheme);
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package pub.doric.navigator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: pub.doric.navigator
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-23
|
||||||
|
*/
|
||||||
|
public interface IDoricNavigator {
|
||||||
|
void push(String scheme, String alias);
|
||||||
|
|
||||||
|
void pop();
|
||||||
|
}
|
@ -32,7 +32,6 @@ import pub.doric.extension.bridge.DoricPromise;
|
|||||||
import pub.doric.utils.DoricUtils;
|
import pub.doric.utils.DoricUtils;
|
||||||
import pub.doric.utils.ThreadMode;
|
import pub.doric.utils.ThreadMode;
|
||||||
|
|
||||||
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.JSValue;
|
||||||
@ -51,7 +50,7 @@ public class ModalPlugin extends DoricJavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DoricMethod(thread = ThreadMode.UI)
|
@DoricMethod(thread = ThreadMode.UI)
|
||||||
public void toast(JSDecoder decoder, DoricPromise promise) {
|
public void toast(JSDecoder decoder) {
|
||||||
try {
|
try {
|
||||||
JSObject jsObject = decoder.decode().asObject();
|
JSObject jsObject = decoder.decode().asObject();
|
||||||
String msg = jsObject.getProperty("msg").asString().value();
|
String msg = jsObject.getProperty("msg").asString().value();
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package pub.doric.plugin;
|
||||||
|
|
||||||
|
import com.github.pengfeizhou.jscore.ArchiveException;
|
||||||
|
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||||
|
import com.github.pengfeizhou.jscore.JSObject;
|
||||||
|
|
||||||
|
import pub.doric.DoricContext;
|
||||||
|
import pub.doric.extension.bridge.DoricMethod;
|
||||||
|
import pub.doric.extension.bridge.DoricPlugin;
|
||||||
|
import pub.doric.navigator.IDoricNavigator;
|
||||||
|
import pub.doric.utils.ThreadMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: pub.doric.plugin
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-23
|
||||||
|
*/
|
||||||
|
@DoricPlugin(name = "navigator")
|
||||||
|
public class NavigatorPlugin extends DoricJavaPlugin {
|
||||||
|
public NavigatorPlugin(DoricContext doricContext) {
|
||||||
|
super(doricContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DoricMethod(thread = ThreadMode.UI)
|
||||||
|
public void push(JSDecoder jsDecoder) {
|
||||||
|
IDoricNavigator navigator = getDoricContext().getDoricNavigator();
|
||||||
|
if (navigator != null) {
|
||||||
|
try {
|
||||||
|
JSObject jsObject = jsDecoder.decode().asObject();
|
||||||
|
navigator.push(jsObject.getProperty("scheme").asString().value(),
|
||||||
|
jsObject.getProperty("alias").asString().value()
|
||||||
|
);
|
||||||
|
} catch (ArchiveException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DoricMethod(thread = ThreadMode.UI)
|
||||||
|
public void pop() {
|
||||||
|
IDoricNavigator navigator = getDoricContext().getDoricNavigator();
|
||||||
|
if (navigator != null) {
|
||||||
|
navigator.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
Android/doric/src/main/res/layout/doric_activity.xml
Normal file
5
Android/doric/src/main/res/layout/doric_activity.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
7
Android/doric/src/main/res/layout/doric_fragment.xml
Normal file
7
Android/doric/src/main/res/layout/doric_fragment.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
</FrameLayout>
|
@ -0,0 +1,5 @@
|
|||||||
|
<?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"
|
||||||
|
android:background="#ffffff" />
|
@ -10,4 +10,5 @@ export default [
|
|||||||
'src/ModalDemo',
|
'src/ModalDemo',
|
||||||
'src/NetworkDemo',
|
'src/NetworkDemo',
|
||||||
'src/StorageDemo',
|
'src/StorageDemo',
|
||||||
|
'src/NavigatorDemo',
|
||||||
]
|
]
|
50
demo/src/NavigatorDemo.ts
Normal file
50
demo/src/NavigatorDemo.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { Panel, scroller, vlayout, text, layoutConfig, LayoutSpec, Color, gravity, IVLayout, Group, IText, navigator } from "doric";
|
||||||
|
import { colors, label } from "./utils";
|
||||||
|
@Entry
|
||||||
|
class NaivgatorDemo extends Panel {
|
||||||
|
build(root: Group) {
|
||||||
|
scroller(vlayout([
|
||||||
|
text({
|
||||||
|
text: "Navigator Demo",
|
||||||
|
layoutConfig: layoutConfig().w(LayoutSpec.AT_MOST),
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
bgColor: colors[1],
|
||||||
|
textAlignment: gravity().center(),
|
||||||
|
height: 50,
|
||||||
|
}),
|
||||||
|
...['Counter', 'EffectsDemo', 'ImageDemo', 'LayoutDemo',
|
||||||
|
'ListDemo', 'ModalDemo', 'NavigatorDemo',
|
||||||
|
'NetworkDemo', 'ScrollerDemo', 'SliderDemo', 'Snake', 'StorageDemo'].map(e =>
|
||||||
|
label(e).apply({
|
||||||
|
height: 50,
|
||||||
|
bgColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().exactly().w(LayoutSpec.AT_MOST),
|
||||||
|
onClick: () => {
|
||||||
|
navigator(context).push(`assets://demo/${e}.js`, `${e}.js`)
|
||||||
|
},
|
||||||
|
} as IText)
|
||||||
|
),
|
||||||
|
label('POP').apply({
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
bgColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().exactly(),
|
||||||
|
onClick: () => {
|
||||||
|
navigator(context).pop()
|
||||||
|
},
|
||||||
|
} as IText),
|
||||||
|
]).apply({
|
||||||
|
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
|
||||||
|
gravity: gravity().center(),
|
||||||
|
space: 10,
|
||||||
|
} as IVLayout)).apply({
|
||||||
|
layoutConfig: layoutConfig().atmost(),
|
||||||
|
}).in(root)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,16 +4,10 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "DemoVC.h"
|
#import "DemoVC.h"
|
||||||
#import "DoricContext.h"
|
#import "Doric.h"
|
||||||
#import "DoricLayouts.h"
|
|
||||||
#import "DoricExtensions.h"
|
|
||||||
#import "DoricRootNode.h"
|
|
||||||
#import "DoricLocalServer.h"
|
|
||||||
|
|
||||||
@interface DemoVC ()
|
@interface DemoVC ()
|
||||||
@property(nonatomic, copy) NSString *filePath;
|
@property(nonatomic, copy) NSString *filePath;
|
||||||
@property(nonatomic, strong) DoricContext *doricContext;
|
|
||||||
//@property(nonatomic, strong) DoricLocalServer *localServer;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DemoVC
|
@implementation DemoVC
|
||||||
@ -31,21 +25,15 @@ - (void)viewDidLoad {
|
|||||||
NSString *demoPath = [path stringByAppendingPathComponent:@"demo"];
|
NSString *demoPath = [path stringByAppendingPathComponent:@"demo"];
|
||||||
NSString *fullPath = [demoPath stringByAppendingPathComponent:self.filePath];
|
NSString *fullPath = [demoPath stringByAppendingPathComponent:self.filePath];
|
||||||
NSString *jsContent = [NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:nil];
|
NSString *jsContent = [NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:nil];
|
||||||
self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:self.filePath];
|
DoricPanel *panel = [DoricPanel new];
|
||||||
[self.doricContext.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) {
|
[panel.view also:^(UIView *it) {
|
||||||
it.backgroundColor = [UIColor whiteColor];
|
it.width = self.view.width;
|
||||||
it.layoutConfig = [[DoricLayoutConfig alloc]
|
it.height = self.view.height - 88;
|
||||||
initWithWidth:DoricLayoutAtMost
|
|
||||||
height:DoricLayoutAtMost
|
|
||||||
margin:DoricMarginMake(0, 88, 0, 0)
|
|
||||||
];
|
|
||||||
it.top = 88;
|
it.top = 88;
|
||||||
[self.view addSubview:it];
|
[self.view addSubview:it];
|
||||||
}]];
|
}];
|
||||||
[self.doricContext initContextWithWidth:self.view.width height:self.view.height];
|
[self addChildViewController:panel];
|
||||||
// [self.doricContext.driver connectDevKit:@"ws://192.168.11.38:7777"];
|
[panel config:jsContent alias:self.filePath];
|
||||||
// self.localServer = [[DoricLocalServer alloc] init];
|
|
||||||
// [self.localServer startWithPort:8910];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
@ -58,8 +58,16 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
|
|||||||
[self.navigationController pushViewController:[QRScanViewController new] animated:NO];
|
[self.navigationController pushViewController:[QRScanViewController new] animated:NO];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DemoVC *demoVC = [[DemoVC alloc] initWithPath:self.demoFilePaths[(NSUInteger) indexPath.row]];
|
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
|
||||||
|
if ([file containsString:@"NavigatorDemo"]) {
|
||||||
|
DoricViewController *doricViewController = [[DoricViewController alloc]
|
||||||
|
initWithScheme:[NSString stringWithFormat:@"assets://demo/%@", file]
|
||||||
|
alias:self.demoFilePaths[(NSUInteger) indexPath.row]];
|
||||||
|
[self.navigationController pushViewController:doricViewController animated:NO];
|
||||||
|
} else {
|
||||||
|
DemoVC *demoVC = [[DemoVC alloc] initWithPath:file];
|
||||||
[self.navigationController pushViewController:demoVC animated:NO];
|
[self.navigationController pushViewController:demoVC animated:NO];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -20,3 +20,7 @@
|
|||||||
#import "DoricRootNode.h"
|
#import "DoricRootNode.h"
|
||||||
#import "UIView+Doric.h"
|
#import "UIView+Doric.h"
|
||||||
#import "DoricUtil.h"
|
#import "DoricUtil.h"
|
||||||
|
#import "DoricPanel.h"
|
||||||
|
#import "DoricJSLoaderManager.h"
|
||||||
|
#import "DoricNavigatorProtocol.h"
|
||||||
|
#import "DoricViewController.h"
|
@ -22,13 +22,14 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "DoricDriver.h"
|
#import "DoricDriver.h"
|
||||||
|
#import "DoricNavigatorProtocol.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@class DoricRootNode;
|
@class DoricRootNode;
|
||||||
|
|
||||||
@interface DoricContext : NSObject
|
@interface DoricContext : NSObject
|
||||||
|
@property(nonatomic, weak) id <DoricNavigatorProtocol> navigator;
|
||||||
@property(nonatomic, strong) NSString *contextId;
|
@property(nonatomic, strong) NSString *contextId;
|
||||||
@property(nonatomic, strong) DoricDriver *driver;
|
@property(nonatomic, strong) DoricDriver *driver;
|
||||||
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;
|
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;
|
||||||
|
29
iOS/Pod/Classes/DoricPanel.h
Normal file
29
iOS/Pod/Classes/DoricPanel.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#import "DoricContext.h"
|
||||||
|
#import "DoricNavigatorProtocol.h"
|
||||||
|
|
||||||
|
@interface DoricPanel : UIViewController
|
||||||
|
@property(nonatomic, strong) DoricContext *doricContext;
|
||||||
|
|
||||||
|
- (void)config:(NSString *)script alias:(NSString *)alias;
|
||||||
|
@end
|
49
iOS/Pod/Classes/DoricPanel.m
Normal file
49
iOS/Pod/Classes/DoricPanel.m
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DoricPanel.h"
|
||||||
|
#import "Doric.h"
|
||||||
|
|
||||||
|
@implementation DoricPanel
|
||||||
|
|
||||||
|
- (void)config:(NSString *)script alias:(NSString *)alias {
|
||||||
|
self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias] also:^(DoricContext *it) {
|
||||||
|
if ([self.parentViewController conformsToProtocol:@protocol(DoricNavigatorProtocol)]) {
|
||||||
|
it.navigator = (id <DoricNavigatorProtocol>) self.parentViewController;
|
||||||
|
}
|
||||||
|
[it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) {
|
||||||
|
it.width = self.view.width;
|
||||||
|
it.height = self.view.height;
|
||||||
|
[self.view addSubview:it];
|
||||||
|
}]];
|
||||||
|
[it initContextWithWidth:self.view.width height:self.view.height];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)viewDidAppear:(BOOL)animated {
|
||||||
|
[super viewDidAppear:animated];
|
||||||
|
[self.doricContext onShow];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)viewDidDisappear:(BOOL)animated {
|
||||||
|
[super viewDidDisappear:animated];
|
||||||
|
[self.doricContext onHidden];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -35,6 +35,7 @@
|
|||||||
#import "DoricSliderNode.h"
|
#import "DoricSliderNode.h"
|
||||||
#import "DoricSlideItemNode.h"
|
#import "DoricSlideItemNode.h"
|
||||||
#import "DoricStoragePlugin.h"
|
#import "DoricStoragePlugin.h"
|
||||||
|
#import "DoricNavigatorPlugin.h"
|
||||||
|
|
||||||
@interface DoricRegistry ()
|
@interface DoricRegistry ()
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ - (void)innerRegister {
|
|||||||
[self registerNativePlugin:DoricModalPlugin.class withName:@"modal"];
|
[self registerNativePlugin:DoricModalPlugin.class withName:@"modal"];
|
||||||
[self registerNativePlugin:DoricNetworkPlugin.class withName:@"network"];
|
[self registerNativePlugin:DoricNetworkPlugin.class withName:@"network"];
|
||||||
[self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"];
|
[self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"];
|
||||||
|
[self registerNativePlugin:DoricNavigatorPlugin.class withName:@"navigator"];
|
||||||
|
|
||||||
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
||||||
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
|
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
|
||||||
|
25
iOS/Pod/Classes/DoricViewController.h
Normal file
25
iOS/Pod/Classes/DoricViewController.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "DoricNavigatorProtocol.h"
|
||||||
|
|
||||||
|
@interface DoricViewController : UIViewController <DoricNavigatorProtocol>
|
||||||
|
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias;
|
||||||
|
@end
|
71
iOS/Pod/Classes/DoricViewController.m
Normal file
71
iOS/Pod/Classes/DoricViewController.m
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DoricViewController.h"
|
||||||
|
#import "DoricAsyncResult.h"
|
||||||
|
#import "DoricJSLoaderManager.h"
|
||||||
|
#import "DoricPanel.h"
|
||||||
|
#import "UIView+Doric.h"
|
||||||
|
#import "DoricExtensions.h"
|
||||||
|
|
||||||
|
@implementation DoricViewController
|
||||||
|
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias {
|
||||||
|
if (self = [super init]) {
|
||||||
|
[self push:scheme alias:alias];
|
||||||
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"
|
||||||
|
style:UIBarButtonItemStylePlain
|
||||||
|
target:self
|
||||||
|
action:@selector(pop)];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)push:(NSString *)scheme alias:(NSString *)alias {
|
||||||
|
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:scheme];
|
||||||
|
result.resultCallback = ^(NSString *result) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
DoricPanel *panel = [DoricPanel new];
|
||||||
|
[panel.view also:^(UIView *it) {
|
||||||
|
it.backgroundColor = [UIColor whiteColor];
|
||||||
|
it.width = self.view.width;
|
||||||
|
it.height = self.view.height - 88;
|
||||||
|
it.top = 88;
|
||||||
|
}];
|
||||||
|
[self.view addSubview:panel.view];
|
||||||
|
[self addChildViewController:panel];
|
||||||
|
[panel config:result alias:alias];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)pop {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
if (self.childViewControllers.count > 1) {
|
||||||
|
[self.childViewControllers.lastObject also:^(UIViewController *it) {
|
||||||
|
[it removeFromParentViewController];
|
||||||
|
[it.view removeFromSuperview];
|
||||||
|
}];
|
||||||
|
} else {
|
||||||
|
[self.navigationController popViewControllerAnimated:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -21,11 +21,11 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "DoricJSExecutorProtocal.h"
|
#import "DoricJSExecutorProtocol.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface DoricJSCoreExecutor : NSObject <DoricJSExecutorProtocal>
|
@interface DoricJSCoreExecutor : NSObject <DoricJSExecutorProtocol>
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "DoricJSEngine.h"
|
#import "DoricJSEngine.h"
|
||||||
#import "DoricJSExecutorProtocal.h"
|
#import "DoricJSExecutorProtocol.h"
|
||||||
#import "DoricJSCoreExecutor.h"
|
#import "DoricJSCoreExecutor.h"
|
||||||
#import "DoricJSRemoteExecutor.h"
|
#import "DoricJSRemoteExecutor.h"
|
||||||
#import "DoricConstant.h"
|
#import "DoricConstant.h"
|
||||||
@ -29,7 +29,7 @@
|
|||||||
#import "DoricBridgeExtension.h"
|
#import "DoricBridgeExtension.h"
|
||||||
|
|
||||||
@interface DoricJSEngine ()
|
@interface DoricJSEngine ()
|
||||||
@property(nonatomic, strong) id <DoricJSExecutorProtocal> jsExecutor;
|
@property(nonatomic, strong) id <DoricJSExecutorProtocol> jsExecutor;
|
||||||
@property(nonatomic, strong) NSMutableDictionary *timers;
|
@property(nonatomic, strong) NSMutableDictionary *timers;
|
||||||
@property(nonatomic, strong) DoricBridgeExtension *bridgeExtension;
|
@property(nonatomic, strong) DoricBridgeExtension *bridgeExtension;
|
||||||
@end
|
@end
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@protocol DoricJSExecutorProtocal <NSObject>
|
@protocol DoricJSExecutorProtocol <NSObject>
|
||||||
|
|
||||||
- (NSString *)loadJSScript:(NSString *)script source:(NSString *)source;
|
- (NSString *)loadJSScript:(NSString *)script source:(NSString *)source;
|
||||||
|
|
@ -21,11 +21,11 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "DoricJSExecutorProtocal.h"
|
#import "DoricJSExecutorProtocol.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface DoricJSRemoteExecutor : NSObject <DoricJSExecutorProtocal>
|
@interface DoricJSRemoteExecutor : NSObject <DoricJSExecutorProtocol>
|
||||||
|
|
||||||
@property(nonatomic, strong) dispatch_semaphore_t semaphore;
|
@property(nonatomic, strong) dispatch_semaphore_t semaphore;
|
||||||
|
|
||||||
|
25
iOS/Pod/Classes/Loader/DoricHttpJSLoader.h
Normal file
25
iOS/Pod/Classes/Loader/DoricHttpJSLoader.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#import "DoricLoaderProtocol.h"
|
||||||
|
|
||||||
|
@interface DoricHttpJSLoader : NSObject <DoricLoaderProtocol>
|
||||||
|
@end
|
45
iOS/Pod/Classes/Loader/DoricHttpJSLoader.m
Normal file
45
iOS/Pod/Classes/Loader/DoricHttpJSLoader.m
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DoricHttpJSLoader.h"
|
||||||
|
|
||||||
|
|
||||||
|
@implementation DoricHttpJSLoader
|
||||||
|
|
||||||
|
- (BOOL)filter:(NSString *)scheme {
|
||||||
|
return [scheme hasPrefix:@"http"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme {
|
||||||
|
DoricAsyncResult *ret = [DoricAsyncResult new];
|
||||||
|
NSURL *URL = [NSURL URLWithString:scheme];
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
|
||||||
|
[[[NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]
|
||||||
|
dataTaskWithRequest:request
|
||||||
|
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
||||||
|
if (!error) {
|
||||||
|
NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||||
|
[ret setupResult:dataStr];
|
||||||
|
} else {
|
||||||
|
[ret setupError:[[NSException alloc] initWithName:@"DoricJSLoaderManager Exception" reason:error.description userInfo:nil]];
|
||||||
|
}
|
||||||
|
}] resume];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@end
|
33
iOS/Pod/Classes/Loader/DoricJSLoaderManager.h
Normal file
33
iOS/Pod/Classes/Loader/DoricJSLoaderManager.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// DoricJSLoaderManager.h
|
||||||
|
// Doric
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "DoricLoaderProtocol.h"
|
||||||
|
#import "DoricAsyncResult.h"
|
||||||
|
|
||||||
|
@interface DoricJSLoaderManager : NSObject
|
||||||
|
+ (instancetype)instance;
|
||||||
|
|
||||||
|
- (void)addJSLoader:(id <DoricLoaderProtocol>)loader;
|
||||||
|
|
||||||
|
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme;
|
||||||
|
@end
|
68
iOS/Pod/Classes/Loader/DoricJSLoaderManager.m
Normal file
68
iOS/Pod/Classes/Loader/DoricJSLoaderManager.m
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// DoricJSLoaderManager.m
|
||||||
|
// Doric
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DoricJSLoaderManager.h"
|
||||||
|
#import "DoricMainBundleJSLoader.h"
|
||||||
|
#import "DoricHttpJSLoader.h"
|
||||||
|
#import "Doric.h"
|
||||||
|
|
||||||
|
@interface DoricJSLoaderManager ()
|
||||||
|
@property(nonatomic, copy) NSSet <id <DoricLoaderProtocol>> *loaders;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation DoricJSLoaderManager
|
||||||
|
+ (instancetype)instance {
|
||||||
|
static DoricJSLoaderManager *_instance;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
_instance = [DoricJSLoaderManager new];
|
||||||
|
});
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
if (self = [super init]) {
|
||||||
|
_loaders = [[NSSet alloc] initWithArray:@[
|
||||||
|
[DoricMainBundleJSLoader new],
|
||||||
|
[DoricHttpJSLoader new],
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)addJSLoader:(id <DoricLoaderProtocol>)loader {
|
||||||
|
self.loaders = [[self.loaders mutableCopy] also:^(NSMutableSet *it) {
|
||||||
|
[it addObject:loader];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme {
|
||||||
|
__block DoricAsyncResult *ret;
|
||||||
|
[self.loaders enumerateObjectsUsingBlock:^(id <DoricLoaderProtocol> obj, BOOL *stop) {
|
||||||
|
if ([obj filter:scheme]) {
|
||||||
|
ret = [obj request:scheme];
|
||||||
|
*stop = YES;
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@end
|
27
iOS/Pod/Classes/Loader/DoricLoaderProtocol.h
Normal file
27
iOS/Pod/Classes/Loader/DoricLoaderProtocol.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "DoricAsyncResult.h"
|
||||||
|
|
||||||
|
@protocol DoricLoaderProtocol <NSObject>
|
||||||
|
- (BOOL)filter:(NSString *)scheme;
|
||||||
|
|
||||||
|
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme;
|
||||||
|
@end
|
25
iOS/Pod/Classes/Loader/DoricMainBundleJSLoader.h
Normal file
25
iOS/Pod/Classes/Loader/DoricMainBundleJSLoader.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#import "DoricLoaderProtocol.h"
|
||||||
|
|
||||||
|
@interface DoricMainBundleJSLoader : NSObject <DoricLoaderProtocol>
|
||||||
|
@end
|
42
iOS/Pod/Classes/Loader/DoricMainBundleJSLoader.m
Normal file
42
iOS/Pod/Classes/Loader/DoricMainBundleJSLoader.m
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DoricMainBundleJSLoader.h"
|
||||||
|
|
||||||
|
|
||||||
|
@implementation DoricMainBundleJSLoader
|
||||||
|
- (BOOL)filter:(NSString *)scheme {
|
||||||
|
return [scheme hasPrefix:@"assets"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (DoricAsyncResult <NSString *> *)request:(NSString *)scheme {
|
||||||
|
DoricAsyncResult <NSString *> *ret = [DoricAsyncResult new];
|
||||||
|
NSString *path = [[NSBundle mainBundle] bundlePath];
|
||||||
|
NSString *fullPath = [path stringByAppendingPathComponent:[scheme substringFromIndex:@"assets://".length]];
|
||||||
|
NSError *error;
|
||||||
|
NSString *jsContent = [NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:&error];
|
||||||
|
if (error) {
|
||||||
|
[ret setupError:[NSException new]];
|
||||||
|
} else {
|
||||||
|
[ret setupResult:jsContent];
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
11
iOS/Pod/Classes/Navigator/DoricNavigatorProtocol.h
Normal file
11
iOS/Pod/Classes/Navigator/DoricNavigatorProtocol.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@protocol DoricNavigatorProtocol <NSObject>
|
||||||
|
- (void)push:(NSString *)scheme alias:(NSString *)alias;
|
||||||
|
|
||||||
|
- (void)pop;
|
||||||
|
@end
|
24
iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.h
Normal file
24
iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "DoricNativePlugin.h"
|
||||||
|
|
||||||
|
@interface DoricNavigatorPlugin : DoricNativePlugin
|
||||||
|
@end
|
31
iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.m
Normal file
31
iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.m
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DoricNavigatorPlugin.h"
|
||||||
|
|
||||||
|
|
||||||
|
@implementation DoricNavigatorPlugin
|
||||||
|
- (void)push:(NSDictionary *)params {
|
||||||
|
[self.doricContext.navigator push:params[@"scheme"] alias:params[@"alias"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)pop {
|
||||||
|
[self.doricContext.navigator pop];
|
||||||
|
}
|
||||||
|
@end
|
@ -26,15 +26,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
|
|
||||||
@interface DoricAsyncResult <R> : NSObject
|
@interface DoricAsyncResult <R> : NSObject
|
||||||
typedef void(^DoricResultCallback)(R);
|
@property(nonatomic, strong) void (^resultCallback)(R result);
|
||||||
|
@property(nonatomic, strong) void (^exceptionCallback)(NSException *e);
|
||||||
typedef void(^DoricExceptionCallback)(NSException *);
|
@property(nonatomic, strong) void (^finishCallback)(void);
|
||||||
|
|
||||||
typedef void(^DoricFinishCallback)(void);
|
|
||||||
|
|
||||||
@property(nonatomic, strong) DoricResultCallback resultCallback;
|
|
||||||
@property(nonatomic, strong) DoricExceptionCallback exceptionCallback;
|
|
||||||
@property(nonatomic, strong) DoricFinishCallback finishCallback;
|
|
||||||
|
|
||||||
- (void)setupResult:(R)result;
|
- (void)setupResult:(R)result;
|
||||||
|
|
||||||
|
@ -56,24 +56,24 @@ - (id)getResult {
|
|||||||
return self.result;
|
return self.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setResultCallback:(DoricResultCallback)callback {
|
- (void)setResultCallback:(void (^)(id))callback {
|
||||||
_resultCallback = callback;
|
_resultCallback = callback;
|
||||||
if (self.result && ![self.result isKindOfClass:[NSException class]]) {
|
if (self.result && ![self.result isKindOfClass:[NSException class]]) {
|
||||||
callback(self.result);
|
callback(self.result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setExceptionCallback:(DoricExceptionCallback)exceptionCallback {
|
- (void)setExceptionCallback:(void (^)(NSException *))exceptionCallback {
|
||||||
_exceptionCallback = exceptionCallback;
|
_exceptionCallback = exceptionCallback;
|
||||||
if ([self.result isKindOfClass:[NSException class]]) {
|
if ([self.result isKindOfClass:[NSException class]]) {
|
||||||
exceptionCallback(self.result);
|
exceptionCallback(self.result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFinishCallback:(DoricFinishCallback)callback {
|
- (void)setFinishCallback:(void (^)(void))finishCallback {
|
||||||
_finishCallback = callback;
|
_finishCallback = finishCallback;
|
||||||
if (self.result) {
|
if (self.result) {
|
||||||
callback();
|
finishCallback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ export abstract class Panel {
|
|||||||
this.__data__ = data
|
this.__data__ = data
|
||||||
this.__root__.width = frame.width
|
this.__root__.width = frame.width
|
||||||
this.__root__.height = frame.height
|
this.__root__.height = frame.height
|
||||||
|
this.__root__.children.length = 0
|
||||||
this.build(this.__root__)
|
this.build(this.__root__)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,3 +167,16 @@ export function storage(context: BridgeContext) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function navigator(context: BridgeContext) {
|
||||||
|
return {
|
||||||
|
push: (scheme: string, alias: string) => {
|
||||||
|
return context.navigator.push({
|
||||||
|
scheme, alias
|
||||||
|
})
|
||||||
|
},
|
||||||
|
pop: () => {
|
||||||
|
return context.navigator.pop()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user