Skip to content

Commit

Permalink
Merge branch 'main' into nested_opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
iPel authored Nov 24, 2023
2 parents dc482d9 + bb9b7db commit 0e96ee6
Show file tree
Hide file tree
Showing 33 changed files with 548 additions and 814 deletions.
2 changes: 1 addition & 1 deletion docs/api/hippy-react/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import icon from './qb_icon_new.png';
| onLayout | 当元素挂载或者布局改变的时候调用,参数为: `nativeEvent: { layout: { x, y, width, height } }`,其中 `x``y` 为相对父元素的坐标位置 | `Function` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onLoad | 加载成功完成时调用此回调函数。 | `Function` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onLoadStart | 加载开始时调用。 例如, `onLoadStart={() => this.setState({ loading: true })}` | `Function` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onLoadEnd | 加载结束后,不论成功还是失败,调用此回调函数。 | `Function` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onLoadEnd | 加载结束后,不论成功还是失败,调用此回调函数。参数为:`nativeEvent: { success: number, width: number, height: number}` | `Function` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| resizeMode | 决定当组件尺寸和图片尺寸不成比例的时候如何调整图片的大小。`注意:hippy-react-web、Web-Renderer 不支持 repeat` | `enum (cover, contain, stretch, repeat, center)` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onError | 当加载错误的时候调用此回调函数,参数为 `nativeEvent: { error }` | `Function` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onProgress | 在加载过程中不断调用,参数为 `nativeEvent: { loaded: number, total: number }`, `loaded` 表示加载中的图片大小, `total` 表示图片总大小 | `Function` | `iOS、Voltron` |
Expand Down
2 changes: 1 addition & 1 deletion docs/api/hippy-vue/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
| layout | 当元素挂载或者布局改变的时候调用,参数为: `nativeEvent: { layout: { x, y, width, height } }`,其中 `x``y` 为相对父元素的坐标位置 | `Function` | `Android、iOS、Web-Renderer、Voltron` |
| load | 加载成功完成时调用此回调函数。 | `Function` | `Android、iOS、Web-Renderer、Voltron` |
| loadStart | 加载开始时调用。 | `Function` | `Android、iOS、Web-Renderer、Voltron` |
| loadEnd | 加载结束后,不论成功还是失败,调用此回调函数。 | `Function` | `Android、iOS、Web-Renderer、Voltron` |
| loadEnd | 加载结束后,不论成功还是失败,调用此回调函数。参数为:`nativeEvent: { success: number, width: number, height: number}` | `Function` | `Android、iOS、Web-Renderer、Voltron` |
| error | 当加载错误的时候调用此回调函数。| `Function` | `Android、iOS、Web-Renderer、Voltron` |
| progress | 在加载过程中不断调用,参数为 `nativeEvent: { loaded: number, total: number }`, `loaded` 表示加载中的图片大小, `total` 表示图片总大小 | `Function` | `iOS、Voltron` |
| touchstart | 触屏开始事件,最低支持版本 2.6.2,参数为 `evt: { touches: [{ clientX: number, clientY: number }] }``clientX``clientY` 分别表示点击在屏幕内的绝对位置 | `Function` | `Android、iOS、Web-Renderer、Voltron` |
Expand Down
2 changes: 2 additions & 0 deletions docs/api/style/appearance.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@
| ------ | -------- | --- |
| number \| string | 否 | Android、iOS

> Android API 28 以下仅支持 `normal``400`) 和 `bold``700`)两种字重,其它字重效果需配合 `fontFamily` 实现。
# letterSpacing

文本字符间距
Expand Down
7 changes: 7 additions & 0 deletions dom/src/dom/deserializer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void CheckUint32(uint32_t value) {

footstone::value::HippyValue hippy_value;
deserializer.ReadObject(hippy_value);
footstone::value::SerializerHelper::DestroyBuffer(buffer);
EXPECT_TRUE(hippy_value.GetType() == footstone::value::HippyValue::Type::kNumber);
EXPECT_TRUE(hippy_value.GetNumberType() == footstone::value::HippyValue::NumberType::kUInt32);
EXPECT_TRUE(hippy_value.ToUint32Checked() == value);
Expand All @@ -60,6 +61,7 @@ void CheckInt32(int32_t value) {

footstone::value::HippyValue hippy_value;
deserializer.ReadObject(hippy_value);
footstone::value::SerializerHelper::DestroyBuffer(buffer);
EXPECT_TRUE(hippy_value.GetType() == footstone::value::HippyValue::Type::kNumber);
EXPECT_TRUE(hippy_value.GetNumberType() == footstone::value::HippyValue::NumberType::kInt32);
EXPECT_TRUE(hippy_value.ToInt32Checked() == value);
Expand All @@ -76,6 +78,7 @@ void CheckDouble(double value) {

footstone::value::HippyValue hippy_value;
deserializer.ReadObject(hippy_value);
footstone::value::SerializerHelper::DestroyBuffer(buffer);
EXPECT_TRUE(hippy_value.GetType() == footstone::value::HippyValue::Type::kNumber);
EXPECT_TRUE(hippy_value.GetNumberType() == footstone::value::HippyValue::NumberType::kDouble);
EXPECT_TRUE(hippy_value.ToDoubleChecked() == value);
Expand All @@ -92,6 +95,7 @@ void CheckString(std::string value) {

footstone::value::HippyValue hippy_value;
deserializer.ReadObject(hippy_value);
footstone::value::SerializerHelper::DestroyBuffer(buffer);
EXPECT_TRUE(hippy_value.GetType() == footstone::value::HippyValue::Type::kString);
EXPECT_TRUE(hippy_value.ToStringChecked() == value);
EXPECT_TRUE(hippy_value.ToStringChecked().length() == value.length());
Expand All @@ -108,6 +112,7 @@ void CheckMap(footstone::value::HippyValue::HippyValueObjectType value) {

footstone::value::HippyValue hippy_value;
deserializer.ReadObject(hippy_value);
footstone::value::SerializerHelper::DestroyBuffer(buffer);
EXPECT_TRUE(hippy_value.GetType() == footstone::value::HippyValue::Type::kObject);
EXPECT_TRUE(hippy_value.IsObject());
EXPECT_TRUE(hippy_value.ToObjectChecked().size() == value.size());
Expand All @@ -134,6 +139,7 @@ void CheckArray(footstone::value::HippyValue::HippyValueArrayType value) {

footstone::value::HippyValue hippy_value;
deserializer.ReadObject(hippy_value);
footstone::value::SerializerHelper::DestroyBuffer(buffer);
EXPECT_TRUE(hippy_value.GetType() == footstone::value::HippyValue::Type::kArray);
EXPECT_TRUE(hippy_value.IsArray());
EXPECT_TRUE(hippy_value.ToArrayChecked().size() == value.size());
Expand All @@ -157,6 +163,7 @@ TEST(DeserializerTest, ReadHeader) {
footstone::value::Deserializer deserializer(buffer.first, buffer.second);
deserializer.ReadHeader();
EXPECT_EQ(deserializer.version_, tdf::base::kLatestVersion);
footstone::value::SerializerHelper::DestroyBuffer(buffer);
}

TEST(DeserializerTest, Uint32) {
Expand Down
1 change: 1 addition & 0 deletions dom/src/dom/dom_argument.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ bool DomArgument::ConvertObjectToBson(const footstone::value::HippyValue& hippy_
std::pair<uint8_t*, size_t> pair = serializer.Release();
bson.resize(pair.second);
memcpy(&bson[0], pair.first, sizeof(uint8_t) * pair.second);
footstone::value::SerializerHelper::DestroyBuffer(pair);
return true;
}

Expand Down
6 changes: 4 additions & 2 deletions dom/src/dom/dom_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ DomManager::byte_string DomManager::GetSnapShot(const std::shared_ptr<RootNode>&
Serializer serializer;
serializer.WriteHeader();
serializer.WriteValue(HippyValue(array));
auto ret = serializer.Release();
return {reinterpret_cast<const char*>(ret.first), ret.second};
auto buffer_pair = serializer.Release();
byte_string bs = {reinterpret_cast<const char*>(buffer_pair.first), buffer_pair.second};
footstone::value::SerializerHelper::DestroyBuffer(buffer_pair);
return bs;
}

bool DomManager::SetSnapShot(const std::shared_ptr<RootNode>& root_node, const byte_string& buffer) {
Expand Down
22 changes: 21 additions & 1 deletion dom/src/dom/serializer_unittests.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2022 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* 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.
*/

#define private public
#define protected public

Expand Down Expand Up @@ -124,7 +144,7 @@ void CheckString(footstone::value::Serializer& serializer, std::string value, si

TEST(SerializerTest, Release) {
footstone::value::Serializer serializer;
serializer.Release();
footstone::value::SerializerHelper(serializer.Release());
EXPECT_EQ(serializer.buffer_ == nullptr, true) << "Serializer buffer is not equal to nullptr.";
EXPECT_EQ(serializer.buffer_size_, 0) << "Serializer buffer_size is not equal to 0.";
EXPECT_EQ(serializer.buffer_capacity_, 0) << "Serializer buffer_capacity is not equal to 0.";
Expand Down
4 changes: 4 additions & 0 deletions driver/js/src/napi/jsc/jsc_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,10 @@ std::shared_ptr<CtxValue> JSCCtx::CreateObject(const std::unordered_map<std::sha
}
auto object_key = JSCVM::CreateJSCString(key);
auto ctx_value = std::static_pointer_cast<JSCCtxValue>(it.second);
if (!ctx_value) {
auto error = CreateException("CreateObject ctx_value is nullptr");
return nullptr;
}
JSObjectSetProperty(context_, obj, object_key, ctx_value->value_, kJSPropertyAttributeNone, &exception);
if (exception) {
SetException(std::make_shared<JSCCtxValue>(context_, exception));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.tencent.mtt.hippy.annotation.HippyNativeModule.Thread;
import com.tencent.mtt.hippy.common.HippyArray;
import com.tencent.mtt.hippy.common.Provider;
import com.tencent.mtt.hippy.modules.HippyModulePromise;
import com.tencent.mtt.hippy.modules.Promise;
import com.tencent.mtt.hippy.modules.PromiseImpl;
import com.tencent.mtt.hippy.runtime.builtins.array.JSDenseArray;
Expand Down Expand Up @@ -208,7 +209,11 @@ private Object[] prepareArguments(@NonNull Object args, PromiseImpl promise)
int size = mUseJSValueType ? ((JSDenseArray) args).size() : ((HippyArray) args).size();
for (int i = 0; i < mParamTypes.length; i++) {
Type paramCls = mParamTypes[i];
if (paramCls == Promise.class) {
// It is necessary to be compatible with the HippyModulePromise type here,
// as some host custom modules interface promise parameters are directly defined
// using the HippyModulePromise type, resulting in parameter mismatches when
// calling the interface.
if (paramCls == Promise.class || paramCls == HippyModulePromise.class) {
params[i] = promise;
promise.setNeedResolveBySelf(false);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
public class ImageLoaderModule extends HippyNativeModuleBase {

private final VfsManager mVfsManager;
private static final String ERROR_KEY_MESSAGE = "message";

public ImageLoaderModule(HippyEngineContext context) {
super(context);
Expand All @@ -50,7 +51,9 @@ private void decodeImageData(@NonNull final String url, @NonNull byte[] data, fi
jsObject.set("height", options.outHeight);
promise.resolve(jsObject);
} catch (OutOfMemoryError | Exception e) {
promise.reject("Fetch image failed, url=" + url + ", msg=" + e.getMessage());
JSObject jsObject = new JSObject();
jsObject.set(ERROR_KEY_MESSAGE, "Fetch image failed, url=" + url + ", msg=" + e.getMessage());
promise.reject(jsObject);
}
}

Expand All @@ -64,7 +67,9 @@ private HashMap<String, String> generateRequestParams() {
@HippyMethod(name = "getSize")
public void getSize(final String url, final Promise promise) {
if (TextUtils.isEmpty(url)) {
promise.reject("Url parameter is empty!");
JSObject jsObject = new JSObject();
jsObject.set(ERROR_KEY_MESSAGE, "Url parameter is empty!");
promise.reject(jsObject);
return;
}
mVfsManager.fetchResourceAsync(url, null, generateRequestParams(),
Expand All @@ -77,7 +82,10 @@ public void onFetchCompleted(@NonNull final ResourceDataHolder dataHolder) {
|| bytes.length <= 0) {
String message =
dataHolder.errorMessage != null ? dataHolder.errorMessage : "";
promise.reject("Fetch image failed, url=" + url + ", msg=" + message);
String errorMsg = "Fetch image failed, url=" + url + ", msg=" + message;
JSObject jsObject = new JSObject();
jsObject.set(ERROR_KEY_MESSAGE, errorMsg);
promise.reject(jsObject);
} else {
decodeImageData(url, bytes, promise);
}
Expand Down
13 changes: 13 additions & 0 deletions modules/footstone/include/footstone/serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ enum class SerializationTag : uint8_t {
kEndDenseJSArray = '$',
};

class SerializerHelper {
public:
static void DestroyBuffer(const std::pair<uint8_t*, size_t>& pair) {
if (pair.first) {
free(pair.first);
}
}
};

class Serializer {
public:
Serializer();
Expand All @@ -80,7 +89,11 @@ class Serializer {

void WriteValue(const HippyValue& hippy_value);

/**
* @brief 获取 HippyValue 对应序列化数据,注意 Release 后指针交给外部管理,需要自行释放
*/
std::pair<uint8_t*, size_t> Release();

private:

void WriteOddball(Oddball oddball);
Expand Down
14 changes: 0 additions & 14 deletions modules/ios/base/HippyLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
#import <Foundation/Foundation.h>
#import "HippyDefines.h"

#ifndef HIPPY_LOG_ENABLED
#ifdef DEBUG
#define HIPPY_LOG_ENABLED 1
#else
#define HIPPY_LOG_ENABLED 0
#endif //#ifdef DEBUG
#endif //#ifndef HIPPY_LOG_ENABLED

/**
* Thresholds for logs to display a redbox. You can override these values when debugging
* in order to tweak the default logging behavior.
Expand Down Expand Up @@ -125,13 +117,7 @@ HIPPY_EXTERN void HippyPerformBlockWithLogPrefix(void (^block)(void), NSString *
/**
* Private logging function - ignore this.
*/
#if HIPPY_LOG_ENABLED
#define _HippyLog(lvl, ...) HippyLogNativeInternal(lvl, __FILE__, __LINE__, __VA_ARGS__);
#else
#define _HippyLog(lvl, ...) \
do { \
} while (0)
#endif

HIPPY_EXTERN void HippyLogNativeInternal(HippyLogLevel, const char *, int, NSString *, ...) NS_FORMAT_FUNCTION(4, 5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void NativeRenderManager::CreateRenderNode(std::weak_ptr<RootNode> root_node,
}
uint32_t root_id = root->GetId();

serializer_->Release();
footstone::value::SerializerHelper::DestroyBuffer(serializer_->Release());
serializer_->WriteHeader();

auto len = nodes.size();
Expand Down Expand Up @@ -182,8 +182,8 @@ void NativeRenderManager::CreateRenderNode(std::weak_ptr<RootNode> root_node,
}
serializer_->WriteValue(HippyValue(dom_node_array));
std::pair<uint8_t*, size_t> buffer_pair = serializer_->Release();

CallNativeMethod("createNode", root->GetId(), buffer_pair);
footstone::value::SerializerHelper::DestroyBuffer(buffer_pair);
}

void NativeRenderManager::UpdateRenderNode(std::weak_ptr<RootNode> root_node,
Expand All @@ -201,7 +201,7 @@ void NativeRenderManager::UpdateRenderNode(std::weak_ptr<RootNode> root_node,
}
}

serializer_->Release();
footstone::value::SerializerHelper::DestroyBuffer(serializer_->Release());
serializer_->WriteHeader();

auto len = nodes.size();
Expand Down Expand Up @@ -242,8 +242,8 @@ void NativeRenderManager::UpdateRenderNode(std::weak_ptr<RootNode> root_node,
}
serializer_->WriteValue(HippyValue(dom_node_array));
std::pair<uint8_t*, size_t> buffer_pair = serializer_->Release();

CallNativeMethod("updateNode", root->GetId(), buffer_pair);
footstone::value::SerializerHelper::DestroyBuffer(buffer_pair);
}

void NativeRenderManager::MoveRenderNode(std::weak_ptr<RootNode> root_node,
Expand All @@ -253,7 +253,7 @@ void NativeRenderManager::MoveRenderNode(std::weak_ptr<RootNode> root_node,
return;
}

serializer_->Release();
footstone::value::SerializerHelper::DestroyBuffer(serializer_->Release());
serializer_->WriteHeader();

auto len = nodes.size();
Expand Down Expand Up @@ -295,6 +295,7 @@ void NativeRenderManager::MoveRenderNode(std::weak_ptr<RootNode> root_node,
JNIEnvironment::ClearJEnvException(j_env);
j_env->DeleteLocalRef(j_buffer);
j_env->DeleteLocalRef(j_class);
footstone::value::SerializerHelper::DestroyBuffer(buffer_pair);
}

void NativeRenderManager::DeleteRenderNode(std::weak_ptr<RootNode> root_node,
Expand Down Expand Up @@ -343,7 +344,7 @@ void NativeRenderManager::UpdateLayout(std::weak_ptr<RootNode> root_node,
return;
}

serializer_->Release();
footstone::value::SerializerHelper::DestroyBuffer(serializer_->Release());
serializer_->WriteHeader();

auto len = nodes.size();
Expand All @@ -367,8 +368,8 @@ void NativeRenderManager::UpdateLayout(std::weak_ptr<RootNode> root_node,
}
serializer_->WriteValue(HippyValue(dom_node_array));
std::pair<uint8_t*, size_t> buffer_pair = serializer_->Release();

CallNativeMethod("updateLayout", root->GetId(), buffer_pair);
footstone::value::SerializerHelper::DestroyBuffer(buffer_pair);
}

void NativeRenderManager::MoveRenderNode(std::weak_ptr<RootNode> root_node,
Expand Down Expand Up @@ -637,11 +638,12 @@ void NativeRenderManager::HandleListenerOps(std::weak_ptr<RootNode> root_node,
return;
}

serializer_->Release();
footstone::value::SerializerHelper::DestroyBuffer(serializer_->Release());
serializer_->WriteHeader();
serializer_->WriteValue(HippyValue(event_listener_ops));
std::pair<uint8_t*, size_t> buffer_pair = serializer_->Release();
CallNativeMethod(method_name, root->GetId(), buffer_pair);
footstone::value::SerializerHelper::DestroyBuffer(buffer_pair);
}

void NativeRenderManager::MarkTextDirty(std::weak_ptr<RootNode> weak_root_node, uint32_t node_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private static void callbackScreenShot(View view, Bitmap bitmap, float scale, in
}

private static String bitmapToBase64Str(Bitmap bitmap, float scale, int viewWidth, int viewHeight) {
String result = null;
String result = "";
ByteArrayOutputStream outputStream = null;
try {
if (bitmap != null) {
Expand All @@ -269,6 +269,8 @@ private static String bitmapToBase64Str(Bitmap bitmap, float scale, int viewWidt
byte[] bitmapBytes = outputStream.toByteArray();
result = Base64.encodeToString(bitmapBytes, Base64.NO_WRAP);
}
} catch (IllegalArgumentException e) {
sCacheBitmapRef.clear();
} catch (IOException e) {
LogUtils.e(TAG, "bitmapToBase64Str, scale exception:", e);
} finally {
Expand Down
Loading

0 comments on commit 0e96ee6

Please sign in to comment.