feat:use DoricPanel instead of DoricContext directly

This commit is contained in:
pengfei.zhou 2019-11-23 11:18:54 +08:00
parent e3813266ba
commit a3f1e67db3
7 changed files with 56 additions and 22 deletions

View File

@ -18,7 +18,6 @@ package pub.doric.demo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
@ -30,7 +29,7 @@ import org.greenrobot.eventbus.ThreadMode;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.devkit.DoricContextDebuggable;
import pub.doric.DoricPanel;
import pub.doric.devkit.event.EnterDebugEvent;
import pub.doric.devkit.event.QuitDebugEvent;
import pub.doric.devkit.event.ReloadEvent;
@ -52,14 +51,12 @@ public class DemoActivity extends AppCompatActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String source = getIntent().getStringExtra("source");
FrameLayout frameLayout = new FrameLayout(this);
addContentView(frameLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
DoricPanel doricPanel = new DoricPanel(this);
addContentView(doricPanel, new ViewGroup.LayoutParams(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);
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
doricContext.getRootNode().setRootView(frameLayout);
sensorHelper = new SensorManagerHelper(this);
sensorHelper.setOnShakeListener(new SensorManagerHelper.OnShakeListener() {
@Override
@ -73,17 +70,6 @@ public class DemoActivity extends AppCompatActivity {
});
}
@Override
protected void onResume() {
super.onResume();
doricContext.onShow();
}
@Override
protected void onPause() {
super.onPause();
doricContext.onHidden();
}
@Override
public void onAttachedToWindow() {
@ -95,7 +81,6 @@ public class DemoActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
super.onDestroy();
doricContext.teardown();
EventBus.getDefault().unregister(this);
sensorHelper.stop();
}

View File

@ -66,7 +66,7 @@ public class DoricContext {
return doricContext;
}
public void init(int width, int height) {
public void init(float width, float height) {
this.initParams = new JSONBuilder()
.put("width", width)
.put("height", height).toJSONObject();

View File

@ -25,6 +25,8 @@ import androidx.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import pub.doric.utils.DoricUtils;
/**
* @Description: Doric
* @Author: pengfei.zhou
@ -58,6 +60,10 @@ public class DoricPanel extends FrameLayout {
public void config(DoricContext doricContext) {
mDoricContext = doricContext;
mDoricContext.getRootNode().setRootView(this);
if (getMeasuredState() != 0) {
mDoricContext.init(DoricUtils.px2dp(getMeasuredWidth()), DoricUtils.px2dp(getMeasuredHeight()));
}
}
@Override
@ -68,4 +74,14 @@ public class DoricPanel extends FrameLayout {
public DoricContext getDoricContext() {
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));
}
}
}
}

View File

@ -17,6 +17,7 @@ package pub.doric;
import android.text.TextUtils;
import pub.doric.plugin.NavigatorPlugin;
import pub.doric.plugin.NetworkPlugin;
import pub.doric.plugin.ShaderPlugin;
import pub.doric.plugin.StoragePlugin;
@ -69,6 +70,7 @@ public class DoricRegistry {
this.registerNativePlugin(ModalPlugin.class);
this.registerNativePlugin(NetworkPlugin.class);
this.registerNativePlugin(StoragePlugin.class);
this.registerNativePlugin(NavigatorPlugin.class);
this.registerViewNode(RootNode.class);
this.registerViewNode(TextNode.class);
this.registerViewNode(ImageNode.class);

View File

@ -32,7 +32,6 @@ import pub.doric.extension.bridge.DoricPromise;
import pub.doric.utils.DoricUtils;
import pub.doric.utils.ThreadMode;
import com.github.pengfeizhou.jscore.ArchiveException;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue;

View 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.
*/
package pub.doric.plugin;
import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricPlugin;
/**
* @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);
}
}

View File

@ -56,6 +56,7 @@ export abstract class Panel {
this.__data__ = data
this.__root__.width = frame.width
this.__root__.height = frame.height
this.__root__.children.length = 0
this.build(this.__root__)
}