Skip to content

Commit

Permalink
Merge branch 'main' into feat/layout_cache_clear
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli authored Oct 23, 2024
2 parents 4869164 + e73c63c commit 3c2bb60
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 72 deletions.
9 changes: 9 additions & 0 deletions devtools/devtools-integration/native/src/v8/trace_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ void TraceControl::StartTracing() {
auto trace_config = v8::platform::tracing::TraceConfig::CreateDefaultTraceConfig();
trace_config->SetTraceRecordMode(v8::platform::tracing::TraceRecordMode::RECORD_CONTINUOUSLY);
trace_config->AddIncludedCategory(kTraceIncludedCategoryV8);
trace_config->EnableSystrace();
trace_config->AddIncludedCategory("devtools.timeline");
trace_config->AddIncludedCategory("v8.execute");
trace_config->AddIncludedCategory("disabled-by-default-devtools.timeline");
trace_config->AddIncludedCategory("disabled-by-default-devtools.timeline.frame");
trace_config->AddIncludedCategory("disabled-by-default-devtools.timeline.stack");
trace_config->AddIncludedCategory("disabled-by-default-v8.cpu_profiler");
trace_config->AddIncludedCategory("disabled-by-default-v8.cpu_profiler.hires");
trace_config->AddIncludedCategory("latencyInfo");
v8_trace_control_->StartTracing(trace_config);
tracing_has_start_ = true;
}
Expand Down
7 changes: 7 additions & 0 deletions docs/api/hippy-react/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ import icon from './qb_icon_new.png';
>
>* time: number: 可指定延迟多久后收起 PullHeader,单位ms
### expandPullHeader

> 最低支持版本 `2.14.0`
`() => void` 展开顶部下拉刷新条 PullHeader。当设置了`renderPullHeader`后,可以通过该方法来主动触发下拉刷新的效果。

### collapsePullFooter

> 最低支持版本 `2.14.0`
Expand Down Expand Up @@ -503,6 +509,7 @@ import icon from './qb_icon_new.png';
| ------------------------ | ------------------------------------------------------------ | -------------------------------------------- | -------- |
| bounces | 是否开启回弹效果,默认 `true` | `boolean` | `iOS、Voltron` |
| initialPage | 指定一个数字,用于决定初始化后默认显示的页面 index,默认不指定的时候是0 | `number` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| offscreenPageLimit | 指定一个数字,用于设置最大挂载到view tree的page item数量,默认为1,如果在间隔较大的item之间切换遇到一些刷新闪动问题,可以尝试设置该属性为最大page item count来解决 | `number` | `Android` |
| scrollEnabled | 指定 ViewPager 是否可以滑动,默认为 `true` | `boolean` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onPageSelected | 指定一个函数,当 page 被选中时进行回调。回调参数是一个 event 对象,回调参数: `position: number` - 表示即将滑到的目标 page 的索引 | `(obj: {position: number}) => void` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onPageScroll | 指定一个函数,当 page 被滑动时进行回调。回调参数是一个 event 对象,回调参数 `position: number` - 表示即将滑到的目标 page 的索引,`offset: number` - 当前被选中的 page 的相对位移,取值范围 -1 到 1 | `(obj: {position: number, offset: number}) => void` | `Android、iOS、Web-Renderer、Voltron` |
Expand Down
3 changes: 3 additions & 0 deletions docs/development/android-3.0-upgrade-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@

}
```

7. module注解HippyNativeModule中取消了线程属性的自定义 <br>
3.0中非JSI module调用将统一走hippy-module-Thread线程调用module对应接口,开发者可以根据自己的需要自行切换线程。

</br>

Expand Down
20 changes: 20 additions & 0 deletions docs/development/native-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Hippy SDK 现在所提供的 Adapter 包括:
- `HippyStorageAdapter`:数据库(KEY-VALUE)Adapter。
- `HippyExecutorSupplierAdapter`:线程池 Adapter。
- `HippyEngineMonitorAdapter`:Hippy 引擎状态监控 Adapter。
- `HippyFontScaleAdapter`:自定义字体 Adapter。


## HippyHttpAdapter
Expand Down Expand Up @@ -55,6 +56,25 @@ Hippy SDK 提供默认空实现 `DefaultEngineMonitorAdapter`。当你需要查

用于支持开发者有自定义格式图片的解码需求,需要开发者自行提供接口类实例。

## HippyFontScaleAdapter

Hippy SDK 提供默认的实现 `DefaultFontScaleAdapter`,默认实现中未对字体做任何定制处理,如果需要加载自定义字体或者改变文字显示大小需要实现自定义font adapter并实现以下接口。

``` java
// 返回字体的缩放系数,开发者可以返回自定义缩放系数,来动态改变字体的显示大小
float getFontScale();

// 通过该方法可以替换text中自定义表情字符
CharSequence getEmoticonText(CharSequence text, int fontSize)

// 根据font family和style返回自定义字体的文件路径
String getCustomFontFilePath(String fontFamily, int style);

// 根据font family和style返回自定义字体的Typaeface对象
Typeface getCustomTypeface(String fontFamily, int style);

```



<br/>
Expand Down
22 changes: 18 additions & 4 deletions docs/development/native-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ public class TestModule extends HippyNativeModuleBase

HippyNativeModuleBase 要求增加注解 `@HippyNativeModule`

HippyNativeModule有两个注解参数
HippyNativeModule注解参数

- name:能力名称,js调用时需要通过此访问该能力。
- thread:能力运行的线程。包括 `HippyNativeModule.Thread.DOM`(Dom线程)、`HippyNativeModule.Thread.MAIN`(主线程)、`HippyNativeModule.Thread.BRIDGE`(Bridge线程、默认值)。
- name:module名称,js调用时需要通过此属性找到对应的module实例对象。
- names:module别名,支持同一个module设置不同的名称。
- init:默认为false,即module在首次调用的时候才会进行实例初始化,如果设置为true,在引擎创建时候就会马上创建实例并初始化

> **注意:init参数在非必要的情况下不要设置为true,否则可能增加引擎启动的耗时。**
``` java
@HippyNativeModule(name = "TestModule", thread = HippyNativeModule.Thread.BRIDGE)
@HippyNativeModule(name = "TestModule")
public class TestModule extends HippyNativeModuleBase
{
...
Expand All @@ -65,8 +68,17 @@ public class TestModule extends HippyNativeModuleBase
- Java基本数据类型。
- HippyArray:类似于ArrayList,线程非安全。
- HippyMap:类似于HashMap,线程非安全。
- 基于JSValue的新数据类型:注解参数useJSValueType设置为true时适用。
- Promise:回调JS的触发器,通过 `resolve` 方法返回成功信息给JS。通过 `reject` 方法返回失败实现给JS。

HippyMethod注解参数:

- name:接口名称,js调用时需要通过此参数找到对应的接口信息,并进行反射调用。
- isSync:是否为JSI接口,JSI为同步调用接口,会卡住js线程,只适用于数据结构简单且size较小的数据传输,[JSI特性介绍](feature/feature2.0/jsi.md)
- useJSValueType:接口参数是否使用新数据类型,默认为false,即使用老的HippyMap与HippyArray类型接收参数,设置为true以后参数需要使用基于JSValue为基类的扩展数据类型,[新数据类型介绍](development/type-mapping.md)

> **注意:新数据类型不能与HippyMap或HippyArray相互嵌套混用, 否则会导致数据编解码产生错误。**
```java
@HippyMethod(name="log")
public void log(String msg)
Expand Down Expand Up @@ -105,6 +117,8 @@ public void helloNativeWithPromise(HippyMap hippyMap, Promise promise)
}
```



## 4. 注册Module

然后需要注册这个Module。需要在 `HippyPackage``getNativeModules` 方法中添加这个 Module,这样它才能在JS中被访问到。
Expand Down
4 changes: 2 additions & 2 deletions dom/src/dom/taitank_layout_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TaitankLayoutConsts {
{"inherit", DIRECTION_INHERIT}, {"ltr", DIRECTION_LTR}, {"rtl", DIRECTION_RTL}};
};

static std::shared_ptr<TaitankLayoutConsts> global_layout_consts = nullptr;
static TaitankLayoutConsts* global_layout_consts = nullptr;

#define TAITANK_GET_STYLE_DECL(NAME, TYPE, DEFAULT) \
static TYPE GetStyle##NAME(const std::string& key) { \
Expand Down Expand Up @@ -828,7 +828,7 @@ void TaitankLayoutNode::Deallocate() {

void InitLayoutConsts() {
if (global_layout_consts == nullptr) {
global_layout_consts = std::make_shared<TaitankLayoutConsts>();
global_layout_consts = new TaitankLayoutConsts();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ module.exports = {
template: path.resolve('./public/index.html'),
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
'process.env': {
NODE_ENV: JSON.stringify('development'),
HOST: JSON.stringify(process.env.DEV_HOST || '127.0.0.1'),
PORT: JSON.stringify(process.env.DEV_PORT || 3000),
},
__PLATFORM__: JSON.stringify(platform),
}),
new CaseSensitivePathsPlugin(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export default class AnimationExample extends React.Component {
duration: 2000,
delay: 0,
mode: 'timing',
valueType: 'deg',
timingFunction: 'linear',
}),
follow: false, // 配置子动画的执行是否跟随执行
Expand All @@ -165,6 +166,7 @@ export default class AnimationExample extends React.Component {
duration: 2000,
delay: 0,
mode: 'timing',
valueType: 'deg',
timingFunction: 'linear',
}),
follow: true,
Expand All @@ -182,6 +184,7 @@ export default class AnimationExample extends React.Component {
duration: 2000,
delay: 0,
mode: 'timing',
valueType: 'deg',
timingFunction: 'linear',
}),
follow: false, // 配置子动画的执行是否跟随执行
Expand All @@ -193,6 +196,7 @@ export default class AnimationExample extends React.Component {
duration: 2000,
delay: 0,
mode: 'timing',
valueType: 'deg',
timingFunction: 'linear',
}),
follow: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ export class ListViewItem extends HippyWebView<HTMLDivElement> {
public handleReLayout(entries: ResizeObserverEntry[]) {
const [entry] = entries;
const { height } = entry.contentRect;
if ((height === 0 && Math.round(height) !== this.height) || Math.round(height) !== this.dom?.clientHeight) {
if ((Math.round(height) === this.height) && Math.round(height) === this.dom?.clientHeight) {
// no need to relayout ListViewItem when height is not changed
return;
}
this.height = Math.round(height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ALIGN_START = 'start';
export const ALIGN_CENTER = 'center';
export const ALIGN_END = 'end';

export default class SizePositionManager {
export default class SizeAndPositionManager {
constructor({
itemCount,
itemSizeGetter,
Expand All @@ -50,24 +50,17 @@ export default class SizePositionManager {
* It just-in-time calculates (or used cached values) for items leading up to the index.
*/
getSizeAndPositionForIndex(index) {
if (index < 0) {
if (index < 0 || index >= this._itemCount) {
throw Error(`Requested index ${index} is outside of range 0..${this._itemCount}`);
}
if(index === 0 && this._itemCount===0){
return 0;
}
if (index >= this._itemCount && this._itemCount!==0) {
index = this._itemCount - 1;
}


if (index > this._lastMeasuredIndex) {
let lastMeasuredSizeAndPosition = this.getSizeAndPositionOfLastMeasuredItem();
let offset = lastMeasuredSizeAndPosition.offset +
lastMeasuredSizeAndPosition.size;
const lastMeasuredSizeAndPosition = this.getSizeAndPositionOfLastMeasuredItem();
let offset = lastMeasuredSizeAndPosition.offset
+ lastMeasuredSizeAndPosition.size;

for (let i = this._lastMeasuredIndex + 1; i <= index; i++) {
let size = this._itemSizeGetter({index: i});
const size = this._itemSizeGetter({ index: i });

if (size == null || isNaN(size)) {
throw Error(`Invalid size returned for index ${i} of value ${size}`);
Expand All @@ -90,7 +83,7 @@ export default class SizePositionManager {
getSizeAndPositionOfLastMeasuredItem() {
return this._lastMeasuredIndex >= 0
? this._itemSizeAndPositionData[this._lastMeasuredIndex]
: {offset: 0, size: 0};
: { offset: 0, size: 0 };
}

/**
Expand All @@ -100,9 +93,7 @@ export default class SizePositionManager {
*/
getTotalSize() {
const lastMeasuredSizeAndPosition = this.getSizeAndPositionOfLastMeasuredItem();
if(this._lastMeasuredIndex === this._itemCount){
return lastMeasuredSizeAndPosition.offset + lastMeasuredSizeAndPosition.size;
}

return lastMeasuredSizeAndPosition.offset + lastMeasuredSizeAndPosition.size + (this._itemCount - this._lastMeasuredIndex - 1) * this._estimatedItemSize;
}

Expand All @@ -111,7 +102,6 @@ export default class SizePositionManager {
*
* @param align Desired alignment within container; one of "start" (default), "center", or "end"
* @param containerSize Size (width or height) of the container viewport
* @param targetIndex index target item
* @return Offset to use to ensure the specified item is visible
*/
getUpdatedOffsetForIndex({
Expand Down Expand Up @@ -146,11 +136,11 @@ export default class SizePositionManager {
return Math.max(0, Math.min(totalSize - containerSize, idealOffset));
}

getVisibleRange({containerSize, offset, overScanCount}) {
getVisibleRange({ containerSize, offset, overscanCount }) {
const totalSize = this.getTotalSize();

if (totalSize === 0) {
return {start:0,stop:0};
return {};
}

const maxOffset = offset + containerSize;
Expand All @@ -165,9 +155,9 @@ export default class SizePositionManager {
offset += this.getSizeAndPositionForIndex(stop).size;
}

if (overScanCount) {
start = Math.max(0, start - overScanCount);
stop = Math.min(stop + overScanCount, this._itemCount-1);
if (overscanCount) {
start = Math.max(0, start - overscanCount);
stop = Math.min(stop + overscanCount, this._itemCount);
}

return {
Expand All @@ -185,7 +175,7 @@ export default class SizePositionManager {
this._lastMeasuredIndex = Math.min(this._lastMeasuredIndex, index - 1);
}

_binarySearch({low, high, offset}) {
_binarySearch({ low, high, offset }) {
let middle;
let currentOffset;

Expand All @@ -195,7 +185,7 @@ export default class SizePositionManager {

if (currentOffset === offset) {
return middle;
} else if (currentOffset < offset) {
} if (currentOffset < offset) {
low = middle + 1;
} else if (currentOffset > offset) {
high = middle - 1;
Expand All @@ -207,12 +197,12 @@ export default class SizePositionManager {
}
}

_exponentialSearch({index, offset}) {
_exponentialSearch({ index, offset }) {
let interval = 1;

while (
index < this._itemCount &&
this.getSizeAndPositionForIndex(index).offset < offset
index < this._itemCount
&& this.getSizeAndPositionForIndex(index).offset < offset
) {
index += interval;
interval *= 2;
Expand Down Expand Up @@ -250,14 +240,13 @@ export default class SizePositionManager {
low: 0,
offset,
});
} else {
// If we haven't yet measured this high, fallback to an exponential search with an inner binary search.
// The exponential search avoids pre-computing sizes for the full set of items as a binary search would.
// The overall complexity for this approach is O(log n).
return this._exponentialSearch({
index: lastMeasuredIndex,
offset,
});
}
// If we haven't yet measured this high, fallback to an exponential search with an inner binary search.
// The exponential search avoids pre-computing sizes for the full set of items as a binary search would.
// The overall complexity for this approach is O(log n).
return this._exponentialSearch({
index: lastMeasuredIndex,
offset,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class VirtualizedList {
});
const fragment = document.createDocumentFragment();

for (let index = start; index <= stop&&stop>0; index++) {
for (let index = start; index <= stop; index++) {
fragment.appendChild(renderRow(index));
}

Expand Down
4 changes: 2 additions & 2 deletions driver/js/src/napi/jsc/jsc_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ constexpr char16_t kSetStr[] = u"set";

static std::once_flag global_class_flag;
static JSClassRef global_class;
static std::shared_ptr<ConstructorDataManager> global_constructor_data_mgr = nullptr;
static ConstructorDataManager* global_constructor_data_mgr = nullptr;

JSCCtx::JSCCtx(JSContextGroupRef group, std::weak_ptr<VM> vm): vm_(vm) {
std::call_once(global_class_flag, []() {
JSClassDefinition global = kJSClassDefinitionEmpty;
global_class = JSClassCreate(&global);
global_constructor_data_mgr = std::make_shared<ConstructorDataManager>();
global_constructor_data_mgr = new ConstructorDataManager();
});

context_ = JSGlobalContextCreateInGroup(group, global_class);
Expand Down
Loading

0 comments on commit 3c2bb60

Please sign in to comment.