Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into 3.0_doc
Browse files Browse the repository at this point in the history
  • Loading branch information
zealotchen0 committed Jun 14, 2024
2 parents d35b631 + e8047bb commit 31f16e8
Show file tree
Hide file tree
Showing 31 changed files with 946 additions and 628 deletions.
67 changes: 66 additions & 1 deletion docs/development/android-3.0-upgrade-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,69 @@

7. 废弃HippyInstanceContext定义及其相关实现
2.0中基于系统ContextWrapper封了Hippy自己的HippyInstanceContext,并将其作为所有Hippy view的初始化参数,随着3.0 framework和renderer两个子模块的解耦,我们发现HippyInstanceContext设计过于臃肿,已经不再适用于最新的3.0架构,所以我们在最新的3.0版本中废弃了HippyInstanceContext,改用更加轻量化的NativeRenderContext取代,所以开发者需要将自定义组件中使用到HippyInstanceContext的相关实现变更为NativeRenderContext
</br>

8. 废弃support ui下面RecyclerView及其派生类HippyListView相关实现,随着瀑布流组件重构完成,HippyWaterfallView已经与HippyRecyclerView共同派生于系统androidX的RecyclerView,老版本的support ui组件已经可以彻底废弃,因此以下2个目录下所有实现文件已经从sdk中移除
- com/tencent/mtt/supportui/views/recyclerview/
- com/tencent/mtt/hippy/views/list/ </br>
之前开发者如果基于HippyListView派生了自己定义的list view组件,需要修改并适配为继承于HippyRecyclerView

9. HippyRootView下面getLaunchParams方法已被废弃,可以使用HippyEngineContext下面getJsParams接口来替代。

10. 简化HippyHttpRequest类实现,移除了以下接口定义:
- public void setMethod(String method)
- public void setInstanceFollowRedirects(boolean instanceFollowRedirects)
- public void setBody(String body)
- public void setNativeParams(Map<String, Object> nativeParams)
- public void setInitParams(HippyMap initParams)
- public void setInstanceFollowRedirects(boolean instanceFollowRedirects)
</br>
由于mInitParams参数在HippyHttpRequest创建的时候就作为初始化参数传入,后续一些依赖mInitParams获取参数的逻辑封装在HippyHttpRequest内部更合理,所以我们移除了相关的set接口,只保留get接口.
</br>
该项调整对于之前2.x中开发者定义了继承于DefaultHttpAdapter的自定义HippyHttpAdapter,并且使用到HippyHttpRequest相关接口的需要做一定适配,适配过程中也可以参考我们github工程main分支DefaultHttpAdapterHippyHttpRequest具体实现。

11. HippyEngineContext下部分接口调整:
- 新增findViewById(int nodeId),可以通过node id查找对应的view
- 移除getDomManager()与getRenderManager()两个接口,之前通过RenderManager查找view的方法通过上述新增接口替代
- getEngineId()接口转移至HippyEngine类下
- 废弃getInstance(int id)接口,由新增getRootView()和getRootView(int rootId)两个接口替代,目前多root view支持还未完善,所以两个getRootView接口调用效果一致
</br>
如果开发者在之前的2.x版本上使用到以上接口,可以根据自己的需要做相应适配调整

12. HippyViewController下面移除getInnerPath(HippyInstanceContext context, String path)接口实现,之前开发者自定义组件Controller中有Override该接口需要重新适配,3.0 image uri local path的转换在ImageComponent中通过convertToLocalPathIfNeeded(String uri)接口实现,目前暂时还不支持开发者自定义。

13. HippyViewController中onManageChildComplete接口已经被废弃,统一使用onBatchComplete接口替代,之前2.x列表滚动过程中,view复用后默认都会调用onManageChildComplete,但3.x中为了减少一些无效的调用逻辑进一步提升列表滚动流畅性,列表滚动view复用的时候默认不会调用onBatchComplete,如果想接收onBatchComplete调用做一些定制逻辑需要做以下适配:
- 定义自定义组件对应的RenderNode(类名自定义),并Override shouldNotifyNonBatchingChange接口

```java
public class CustomRenderNode extends RenderNode {

public CustomRenderNode(int rootId, int id,
@Nullable Map<String, Object> props,
String className,
ControllerManager componentManager,
boolean isLazyLoad) {
super(rootId, id, props, className, componentManager, isLazyLoad);
}

@Override
protected boolean shouldNotifyNonBatchingChange() {
return !isBatching();
}
}
```

- 在自定义组件ControllerOverride createRenderNode接口并增加自定义RenderNode的创建逻辑

```java
@Override
public RenderNode createRenderNode(int rootId, int id,
@Nullable Map<String, Object> props,
@NonNull String className,
@NonNull ControllerManagercontrollerManager,
boolean isLazy) {
return new CustomRenderNode(rootId, id, props, className, controllerManager, isLazy);
}
```

# 新增特性适配项(optional)

Expand Down Expand Up @@ -120,3 +182,6 @@
```

为了减低3.0升级的成本原来使用HippyArray类型的接口还是保留,只是标记为@Deprecated,所以升级3.0对于原来定义的dispatchFunction接口不需要做任何修改,但建议后续升级到3.0版本定义新UI组件的时候,直接Override使用List参数类型的新接口。

5. HippyEngine中新增Screenshot截屏特性接口
过去在一些业务的使用场景中需要针对指定的Hippy view进行截图并做分享,之前截图逻辑都是由开发者自己实现,为了进一步降低开发者的适配成本,我们把截图能力下沉到了SDK,为开发者提供更为便捷的使用方式,关于Screenshot截屏特性与接口使用的介绍可以详见 [Screenshot for specific views](feature/feature3.0/screenshot.md)。
1 change: 1 addition & 0 deletions docs/feature/feature3.0/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [Snapshot](feature/feature3.0/render-node-snapshot.md)
- [双端一致性](feature/feature3.0/cross-platform-consistency.md)
- [Performance API](feature/feature3.0/performance.md)
- [Screenshot](feature/feature3.0/screenshot.md)
- 2.0+
- [动画](feature/feature2.0/animation.md)
- [日志](feature/feature2.0/console.md)
Expand Down
42 changes: 42 additions & 0 deletions docs/feature/feature3.0/screenshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Screenshot for specific views

---

## 背景

过去在一些业务的使用场景中需要针对指定的Hippy view进行截图并做分享,之前截图逻辑都是由开发者自己实现,在3.0中我们针对图片解码使用了Android高版本的api,导致部分开发者自己创建canvas和bitmap,并用draw方法截图的方式无法正常截取图片,为了进一步降低开发者的适配成本,我们把截图能力下沉到了SDK,为开发者提供更为便捷的使用方式。

## 3.0 Screenshot接口定义

### HippyEngine Public methods

```java
/**
* @throws IllegalArgumentException
*/
public abstract void getScreenshotBitmapForView(@Nullable Context context,
int id, @NonNull ScreenshotBuildCallback callback);
```

针对指定id的View进行截图,context非空情况下需要是HippyRootView挂载容器所属的Activity

```java
/**
* @throws IllegalArgumentException
*/
public abstract void getScreenshotBitmapForView(@Nullable Context context,
@NonNull View view, @NonNull ScreenshotBuildCallback callback);
```

针对指定的View进行截图,context非空情况下需要是HippyRootView挂载容器所属的Activity

> 注意:以上2个接口中的context参数如果传入null,会默认使用view的context,view设置的context是loadModule时候在ModuleLoadParams中传入的context,针对一些预加载场景,开发者有可能设置的是app的context,当context不是Activiy的时候会抛出IllegalArgumentException异常导致截图失败。除了context不满足条件,还有其它view不存在或者执行PixelCopy.request都有可能抛出IllegalArgumentException类型异常,需要开发者自行捕获处理。
```java
public interface ScreenshotBuildCallback {

void onScreenshotBuildCompleted(Bitmap bitmap, int result);
}
```

返回截图结果的回调,result为0代表截图成功,非0代表截图失败,失败错误值可以参考系统PixelCopy类中定义的错误码
3 changes: 2 additions & 1 deletion dom/src/dom/animation/animation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ void Animation::Run(uint64_t now, const AnimationOnRun& on_run) {
case Animation::Status::kDestroy:
default: {
FOOTSTONE_LOG(ERROR) << "animation status = " << static_cast<uint32_t>(status_);
FOOTSTONE_UNREACHABLE();
FOOTSTONE_DCHECK(false);
return;
}
}

Expand Down
10 changes: 2 additions & 8 deletions driver/js/src/napi/jsc/jsc_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,7 @@ bool JSCCtx::Equals(const std::shared_ptr<CtxValue>& lhs, const std::shared_ptr<
}

std::shared_ptr<CtxValue> JSCCtx::CreateObject() {
JSClassDefinition fn_def = kJSClassDefinitionEmpty;
JSClassRef cls_ref = JSClassCreate(&fn_def);
JSObjectRef fn_obj = JSObjectMake(context_, cls_ref, nullptr);
JSClassRelease(cls_ref);
JSObjectRef fn_obj = JSObjectMake(context_, nullptr, nullptr);
return std::make_shared<JSCCtxValue>(context_, fn_obj);
}

Expand Down Expand Up @@ -776,10 +773,7 @@ std::shared_ptr<CtxValue> JSCCtx::CreateObject(const std::unordered_map<
}

std::shared_ptr<CtxValue> JSCCtx::CreateObject(const std::unordered_map<std::shared_ptr<CtxValue>, std::shared_ptr<CtxValue>> &object) {
JSClassDefinition cls_def = kJSClassDefinitionEmpty;
JSClassRef cls_ref = JSClassCreate(&cls_def);
JSObjectRef obj = JSObjectMake(context_, cls_ref, nullptr);
JSClassRelease(cls_ref);
JSObjectRef obj = JSObjectMake(context_, nullptr, nullptr);
JSValueRef exception = nullptr;
for (const auto& it : object) {
string_view key;
Expand Down
6 changes: 4 additions & 2 deletions framework/android/connector/dom/src/main/cpp/src/dom_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ void ReleaseRootResources(JNIEnv* j_env,
auto& persistent_map = RootNode::PersistentMap();
std::shared_ptr<RootNode> root_node;
auto flag = persistent_map.Find(root_id, root_node);
FOOTSTONE_CHECK(flag);
root_node->ReleaseResources();
FOOTSTONE_DCHECK(flag);
if (flag) {
root_node->ReleaseResources();
}
}

void SetDomManager(JNIEnv* j_env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ std::tuple<bool, std::string, jobject> ConvertUtils::ToHippyMap(const std::share

auto to_jobject_tuple = ToJObject(ctx, item);
if (!std::get<0>(to_jobject_tuple)) {
j_env->DeleteLocalRef(key_j_obj);
return std::make_tuple(false, std::get<1>(to_jobject_tuple), static_cast<jobject>(nullptr));
}
jobject value_j_obj = std::get<2>(to_jobject_tuple);
Expand Down Expand Up @@ -644,6 +645,7 @@ std::tuple<bool,
} else if (!obj) {
result = ctx->CreateNull();
} else {
j_env->DeleteLocalRef(obj);
return std::make_tuple(false, "UnSupported Type in HippyArray or HippyMap",
static_cast<std::shared_ptr<CtxValue>>(nullptr));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,14 @@ std::shared_ptr<Scope> GetScope(jint j_scope_id) {

void OnNativeInitEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong startTime, jlong endTime) {
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
if (!scope) {
return;
}
auto engine = scope->GetEngine().lock();
if (!engine) {
return;
}
auto runner = engine->GetJsTaskRunner();
if (runner) {
std::weak_ptr<Scope> weak_scope = scope;
auto task = [weak_scope, startTime, endTime]() {
Expand All @@ -187,7 +194,14 @@ void OnNativeInitEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong sta

void OnFirstPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time) {
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
if (!scope) {
return;
}
auto engine = scope->GetEngine().lock();
if (!engine) {
return;
}
auto runner = engine->GetJsTaskRunner();
if (runner) {
std::weak_ptr<Scope> weak_scope = scope;
auto task = [weak_scope, time]() {
Expand All @@ -211,7 +225,14 @@ void OnFirstPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong tim

void OnFirstContentfulPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time) {
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
if (!scope) {
return;
}
auto engine = scope->GetEngine().lock();
if (!engine) {
return;
}
auto runner = engine->GetJsTaskRunner();
if (runner) {
std::weak_ptr<Scope> weak_scope = scope;
auto task = [weak_scope, time]() {
Expand All @@ -235,7 +256,14 @@ void OnResourceLoadEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jstring
auto ret_code = static_cast<int32_t>(j_ret_code);
auto error_msg = j_error_msg ? JniUtils::ToStrView(j_env, j_error_msg) : string_view("");
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
if (!scope) {
return;
}
auto engine = scope->GetEngine().lock();
if (!engine) {
return;
}
auto runner = engine->GetJsTaskRunner();
if (runner) {
std::weak_ptr<Scope> weak_scope = scope;
auto task = [weak_scope, uri, j_start_time, j_end_time, ret_code, error_msg]() {
Expand Down
Loading

0 comments on commit 31f16e8

Please sign in to comment.