Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/modal and snapshot #4182

Merged
merged 5 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/development/android-3.0-integration-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

## 快速接入

1. 创建一个 Android 工程
1. 创建一个 Android 工程 (SDK工程支持的minSdkVersion=21, 宿主工程支持的minSdkVersion不能低于该版本)

2. Maven 集成

Expand Down
1 change: 1 addition & 0 deletions docs/development/android-3.0-upgrade-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
1. ModuleListener接口定义变更 <br>
- onLoadCompleted回调接口移除了root view参数的返回
- 增加onFirstViewAdded接口回调,返回第一view挂载到Hippy root view的回调时机
- 增加onFirstContentfulPaint接口回调,返回FCP节点渲染时机(3.3.3版本新增)

2. HippyEngineContext类中部分接口调整 <br>
- 新增findViewById(int nodeId),可以通过node id查找对应的view
Expand Down
8 changes: 4 additions & 4 deletions docs/feature/feature3.0/render-node-snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public void recordSnapshot(@NonNull View rootView, @NonNull final Callback<byte[
记录指定root view的节点缓存,SDK内部会完成节点遍历,序列化相关的任务,最终通过Callback返回节点序列化后的buffer,节点数据存储,生命周期管理由宿主自行完成

```java
public View replaySnapshot(@NonNull Context context, byte[] buffer)
public View replaySnapshot(@NonNull Context context, byte[] buffer, String bundlePath)
```

传入之前record的buffer回放节点数据,这个接口调用将同步返回还原的view
传入之前record的buffer回放节点数据,这个接口调用将同步返回还原的view,bundlePath为js bundle包的绝对路径,用与replay加载本地图片用

```java
public View replaySnapshot(@NonNull Context context, @NonNull Map<String, Object> snapshotMap)
public View replaySnapshot(@NonNull Context context, @NonNull Map<String, Object> snapshotMap, String bundlePath)
```

传入decode后的节点Map数据,同步返回还原的view
传入decode后的节点Map数据,同步返回还原的view,bundlePath为js bundle包的绝对路径,用与replay加载本地图片用

```java
public View removeSnapshotView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@
import com.tencent.mtt.hippy.utils.LogUtils;
import com.tencent.mtt.hippy.utils.UIThreadUtils;
import com.tencent.mtt.hippy.adapter.thirdparty.HippyThirdPartyAdapter;
import com.tencent.renderer.NativeRenderException;
import com.tencent.renderer.component.image.ImageDecoderAdapter;
import com.tencent.renderer.serialization.Serializer;
import com.tencent.vfs.Processor;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -74,6 +71,7 @@
@SuppressWarnings({"deprecation", "unused", "rawtypes"})
public abstract class HippyEngine {

public static final String TAG = "HippyEngine";
private static final AtomicInteger ID_COUNTER = new AtomicInteger();
private final int engineId = ID_COUNTER.getAndIncrement();

Expand Down Expand Up @@ -210,9 +208,9 @@ public int getEngineId() {

public abstract void recordSnapshot(@NonNull View rootView, @NonNull final Callback<byte[]> callback);

public abstract View replaySnapshot(@NonNull Context context, byte[] buffer);
public abstract View replaySnapshot(@NonNull Context context, byte[] buffer, String bundlePath);

public abstract View replaySnapshot(@NonNull Context context, @NonNull Map<String, Object> snapshotMap);
public abstract View replaySnapshot(@NonNull Context context, @NonNull Map<String, Object> snapshotMap, String bundlePath);

public abstract void removeSnapshotView();

Expand Down Expand Up @@ -479,5 +477,7 @@ public interface ModuleListener {
boolean onJsException(HippyJsException exception);

void onFirstViewAdded();

void onFirstContentfulPaint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import com.tencent.renderer.node.RenderNode;
import com.tencent.vfs.DefaultProcessor;
import com.tencent.vfs.Processor;
import com.tencent.vfs.UrlUtils;
import com.tencent.vfs.VfsManager;
import com.openhippy.connector.JsDriver.V8InitParams;
import java.util.ArrayList;
Expand Down Expand Up @@ -118,6 +119,7 @@ public abstract class HippyEngineManagerImpl extends HippyEngineManager implemen
HippyEngineContextImpl mEngineContext;
private ModuleLoadParams moduleLoadParams;
private HippyBundleLoader jsBundleLoader;
private String mBundlePath = null;
// 从网络上加载jsbundle
final boolean mDebugMode;
// Hippy Server的jsbundle名字,调试模式下有效
Expand Down Expand Up @@ -159,7 +161,7 @@ public abstract class HippyEngineManagerImpl extends HippyEngineManager implemen
mGroupId = params.groupId;
mThirdPartyAdapter = params.thirdPartyAdapter;
v8InitParams = params.v8InitParams;
mMonitor = new TimeMonitor();
mMonitor = new TimeMonitor(getEngineId());
}

@Override
Expand Down Expand Up @@ -249,6 +251,9 @@ public void onFirstContentfulPaint() {
mEngineContext.getJsDriver().recordFirstContentfulPaintEndTime(System.currentTimeMillis());
mEngineContext.getMonitor().endGroup(TimeMonitor.MONITOR_GROUP_PAINT);
mGlobalConfigs.getEngineMonitorAdapter().onFirstContentfulPaintCompleted(mEngineContext.getComponentName());
if (mModuleListener != null) {
mModuleListener.onFirstContentfulPaint();
}
}

@Override
Expand Down Expand Up @@ -337,8 +342,11 @@ public Object getCustomViewCreator() {
public String getBundlePath() {
if (jsBundleLoader != null) {
return jsBundleLoader.getPath();
} else if (mBundlePath != null && !mBundlePath.startsWith(UrlUtils.PREFIX_FILE)
&& !mBundlePath.startsWith(UrlUtils.PREFIX_ASSETS)) {
return UrlUtils.PREFIX_FILE + mBundlePath;
}
return null;
return mBundlePath;
}

@Override
Expand All @@ -358,15 +366,17 @@ public void recordSnapshot(@NonNull View rootView, @NonNull final Callback<byte[
}

@Nullable
public View replaySnapshot(@NonNull Context context, @NonNull byte[] buffer) {
public View replaySnapshot(@NonNull Context context, @NonNull byte[] buffer, String bundlePath) {
mBundlePath = bundlePath;
if (mEngineContext != null) {
return mEngineContext.getRenderer().replaySnapshot(context, buffer);
}
return null;
}

@Nullable
public View replaySnapshot(@NonNull Context context, @NonNull Map<String, Object> snapshotMap) {
public View replaySnapshot(@NonNull Context context, @NonNull Map<String, Object> snapshotMap, String bundlePath) {
mBundlePath = bundlePath;
if (mEngineContext != null) {
return mEngineContext.getRenderer().replaySnapshot(context, snapshotMap);
}
Expand Down Expand Up @@ -756,8 +766,8 @@ public void callback(Boolean result, Throwable e) {
}

/**
* After init engine callback, send load instance message to js invoke render If debug mode js
* bundle load with common bundle after init engine
* After init engine callback, send load instance message to js invoke render If debug mode js bundle load with
* common bundle after init engine
*/
private void loadJsModule() {
if (mEngineContext == null || mRootView == null || moduleLoadParams == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.tencent.mtt.hippy.bridge.bundleloader;

import static com.tencent.mtt.hippy.bridge.HippyBridge.URI_SCHEME_FILE;
import static com.tencent.vfs.UrlUtils.PREFIX_FILE;

import android.text.TextUtils;
import com.tencent.mtt.hippy.bridge.HippyBridge;
Expand All @@ -25,8 +26,6 @@
@SuppressWarnings({"unused"})
public class HippyFileBundleLoader implements HippyBundleLoader {

private static final String FILE_STR = "file://";

final String mFilePath;

private boolean mCanUseCodeCache;
Expand Down Expand Up @@ -64,8 +63,8 @@ public void load(HippyBridge bridge, NativeCallback callback) {

@Override
public String getPath() {
if (mFilePath != null && !mFilePath.startsWith(FILE_STR)) {
return FILE_STR + mFilePath;
if (mFilePath != null && !mFilePath.startsWith(PREFIX_FILE)) {
return PREFIX_FILE + mFilePath;
} else {
return mFilePath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ class HippyEngineWrapper//TODO: Coming soon
if (!isDebugMode && isSnapshotMode) {
val buffer = renderNodeSnapshot[driverMode]
buffer?.let {
snapshotView = hippyEngine.replaySnapshot(context, it)
var bundlePath = "assets://" + loadParams.jsAssetsPath
snapshotView = hippyEngine.replaySnapshot(context, it, bundlePath)
}
snapshotView?.let {
hippySnapshotView = snapshotView as ViewGroup
Expand All @@ -203,6 +204,10 @@ class HippyEngineWrapper//TODO: Coming soon
}, 400)
}
}

override fun onFirstContentfulPaint() {

}
})

val loadCallbackTask = Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@ public class TimeMonitor {
public static final String MONITOR_POINT_LOAD_MAIN_JS = "loadMainJs";
public static final String MONITOR_POINT_FIRST_PAINT = "firstPaint";
public static final String MONITOR_POINT_FIRST_CONTENTFUL_PAINT = "firstContentfulPaint";
private int mEngineId;
@Nullable
HashMap<String, MonitorGroup> mMonitorGroups;

public TimeMonitor(int engineId) {
mEngineId = engineId;
}

public synchronized void beginGroup(@NonNull String groupName) {
if (mMonitorGroups == null) {
mMonitorGroups = new HashMap<>();
}
MonitorGroup monitorGroup = mMonitorGroups.get(groupName);
if (monitorGroup == null) {
monitorGroup = new MonitorGroup(groupName);
monitorGroup = new MonitorGroup(groupName, mEngineId);
mMonitorGroups.put(groupName, monitorGroup);
} else {
monitorGroup.reset();
Expand Down Expand Up @@ -87,13 +92,15 @@ private static class MonitorGroup {
public long beginTime = -1;
public long totalTime = -1;
public boolean isActive = true;
public int engineId = -1;
@Nullable
private ArrayList<MonitorPoint> mMonitorPoints;
@Nullable
private MonitorPoint mLastPoint;

public MonitorGroup(@NonNull String name) {
public MonitorGroup(@NonNull String name, int engineId) {
this.name = name;
this.engineId = engineId;
}

@Nullable
Expand Down Expand Up @@ -157,7 +164,7 @@ void end() {

void print() {
if (mMonitorPoints != null) {
LogUtils.e(TAG, "group " + name + ", totalTime " + totalTime + "ms");
LogUtils.e(TAG, "engine id " + engineId + ", group " + name + ", totalTime " + totalTime + "ms");
for (MonitorPoint monitorPoint : mMonitorPoints) {
LogUtils.e(TAG,
monitorPoint.key + ": " + (monitorPoint.endTime - monitorPoint.startTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.util.SparseArray;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnDrawListener;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
Expand All @@ -46,6 +47,7 @@ public class HippyRootView extends FrameLayout {
protected boolean firstViewAdded = false;
@Nullable
private GlobalLayoutListener mGlobalLayoutListener;
private DrawListener mOnDrawListener;

public HippyRootView(Context context, int instanceId, int rootId) {
super(new NativeRenderContext(context, instanceId, rootId));
Expand All @@ -54,6 +56,7 @@ public HippyRootView(Context context, int instanceId, int rootId) {
setTag(tagMap);
if (rootId != SCREEN_SNAPSHOT_ROOT_ID) {
getViewTreeObserver().addOnGlobalLayoutListener(getGlobalLayoutListener());
getViewTreeObserver().addOnDrawListener(getDrawListener());
}
}

Expand Down Expand Up @@ -115,6 +118,41 @@ protected void onDetachedFromWindow() {
}
}

public void onFcpBatchEnd() {
DrawListener drawListener = getDrawListener();
drawListener.onFcpBatchEnd();
}

private class DrawListener implements ViewTreeObserver.OnDrawListener {

private boolean mFirstContentfulPaint = false;

public void onFcpBatchEnd() {
LogUtils.d(TAG, "onFcpBatchEnd: id " + HippyRootView.this.getId() + ", time " + System.currentTimeMillis());
mFirstContentfulPaint = true;
}

@Override
public void onDraw() {
Context context = getContext();
if (context != null && mFirstContentfulPaint) {
LogUtils.d(TAG, "onDraw: id " + HippyRootView.this.getId() + ", time " + System.currentTimeMillis());
NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(context);
if (nativeRenderer != null) {
nativeRenderer.onFirstContentfulPaint(HippyRootView.this.getId());
}
mFirstContentfulPaint = false;
}
}
}

private DrawListener getDrawListener() {
if (mOnDrawListener == null) {
mOnDrawListener = new DrawListener();
}
return mOnDrawListener;
}

private GlobalLayoutListener getGlobalLayoutListener() {
if (mGlobalLayoutListener == null) {
mGlobalLayoutListener = new GlobalLayoutListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.tencent.mtt.hippy.uimanager;

import static com.tencent.renderer.NativeRenderer.EVENT_PREFIX;
import static com.tencent.renderer.NativeRenderer.SCREEN_SNAPSHOT_ROOT_ID;

import android.graphics.Color;
import android.view.View;
Expand Down Expand Up @@ -279,7 +280,7 @@ protected void updateProps(@NonNull RenderNode node, @NonNull T controller, @Nul
view.setBackgroundColor(
MapUtils.getIntValue(props, NodeProps.BACKGROUND_COLOR,
Color.TRANSPARENT));
} else if (!handleComponentProps(node, key, props, skipComponentProps)) {
} else if (!handleComponentProps(node, key, props, skipComponentProps) && node.getRootId() != SCREEN_SNAPSHOT_ROOT_ID) {
PropertyMethodHolder customMethodHolder = getCustomPropsMethodHolder(key);
if (customMethodHolder != null && view == null) {
// If the host has a custom attribute that needs to be processed, this element cannot be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ protected HippyModalHostView createModalHostView(Context context) {
@Override
public void onViewDestroy(HippyModalHostView hippyModalHostView) {
super.onViewDestroy(hippyModalHostView);
int rootId = NativeRendererManager.getRootId(hippyModalHostView.getContext());
hippyModalHostView.onInstanceDestroy(rootId);
hippyModalHostView.onDestroy();
}

@HippyControllerProps(name = "animationType", defaultType = HippyControllerProps.STRING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public void onInstancePause() {

@Override
public void onInstanceDestroy(int rootId) {
dismiss();
}

public void onDestroy() {
if (mNativeRenderer != null) {
mNativeRenderer.removeInstanceLifecycleEventListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ VirtualNode createVirtualNode(int rootId, int id, int pid, int index, @NonNull S

void onFirstPaint(int rootId);

void onFirstContentfulPaint();
void onFirstContentfulPaint(int rootId);

void onSizeChanged(int rootId, int width, int height, int oldWidth, int oldHeight);

Expand Down
Loading
Loading