optimize: clean view's props after being bunched fetched from native
This commit is contained in:
@@ -17,6 +17,7 @@ import { Stack } from './layouts'
|
||||
import { Property, Superview, View, NativeViewModel } from '../ui/view'
|
||||
import { layoutConfig } from '../util/index.util'
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { deepClone } from './utils';
|
||||
|
||||
export class FlowLayoutItem extends Stack {
|
||||
/**
|
||||
@@ -142,17 +143,20 @@ export class FlowLayout extends Superview {
|
||||
this.cachedViews.clear()
|
||||
this.itemCount = 0
|
||||
}
|
||||
|
||||
private getItem(itemIdx: number) {
|
||||
let view = this.renderItem(itemIdx)
|
||||
view.superview = this
|
||||
this.cachedViews.set(`${itemIdx}`, view)
|
||||
return view
|
||||
}
|
||||
|
||||
private renderBunchedItems(start: number, length: number) {
|
||||
return new Array(Math.min(length, this.itemCount - start)).fill(0).map((_, idx) => {
|
||||
const listItem = this.getItem(start + idx)
|
||||
return listItem.toModel()
|
||||
})
|
||||
const items = new Array(Math.max(0, Math.min(length, this.itemCount - start)))
|
||||
.fill(0).map((_, idx) => this.getItem(start + idx))
|
||||
const ret = items.map(e => deepClone(e.toModel()))
|
||||
items.forEach(e => e.clean())
|
||||
return ret
|
||||
}
|
||||
|
||||
toModel(): NativeViewModel {
|
||||
|
@@ -19,6 +19,7 @@ import { Stack } from "./layouts";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { Color } from "../util/color";
|
||||
import { deepClone } from "./utils";
|
||||
|
||||
export class HorizontalListItem extends Stack {
|
||||
/**
|
||||
@@ -151,10 +152,11 @@ export class HorizontalList extends Superview {
|
||||
}
|
||||
|
||||
private renderBunchedItems(start: number, length: number) {
|
||||
return new Array(Math.max(0, Math.min(length, this.itemCount - start))).fill(0).map((_, idx) => {
|
||||
const listItem = this.getItem(start + idx)
|
||||
return listItem.toModel()
|
||||
})
|
||||
const items = new Array(Math.max(0, Math.min(length, this.itemCount - start)))
|
||||
.fill(0).map((_, idx) => this.getItem(start + idx))
|
||||
const ret = items.map(e => deepClone(e.toModel()))
|
||||
items.forEach(e => e.clean())
|
||||
return ret
|
||||
}
|
||||
|
||||
toModel(): NativeViewModel {
|
||||
|
@@ -19,6 +19,7 @@ import { Stack } from "./layouts";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { Color } from "../util/color";
|
||||
import { deepClone } from "./utils";
|
||||
|
||||
export class ListItem extends Stack {
|
||||
/**
|
||||
@@ -154,10 +155,11 @@ export class List extends Superview {
|
||||
}
|
||||
|
||||
private renderBunchedItems(start: number, length: number) {
|
||||
return new Array(Math.max(0, Math.min(length, this.itemCount - start))).fill(0).map((_, idx) => {
|
||||
const listItem = this.getItem(start + idx)
|
||||
return listItem.toModel()
|
||||
})
|
||||
const items = new Array(Math.max(0, Math.min(length, this.itemCount - start)))
|
||||
.fill(0).map((_, idx) => this.getItem(start + idx))
|
||||
const ret = items.map(e => deepClone(e.toModel()))
|
||||
items.forEach(e => e.clean())
|
||||
return ret
|
||||
}
|
||||
|
||||
toModel(): NativeViewModel {
|
||||
|
@@ -17,6 +17,7 @@ import { Superview, View, Property } from "../ui/view";
|
||||
import { Stack } from "./layouts";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { deepClone } from "./utils";
|
||||
|
||||
|
||||
|
||||
@@ -92,10 +93,11 @@ export class Slider extends Superview {
|
||||
}
|
||||
|
||||
private renderBunchedItems(start: number, length: number) {
|
||||
return new Array(Math.min(length, this.itemCount - start)).fill(0).map((_, idx) => {
|
||||
const slideItem = this.getItem(start + idx)
|
||||
return slideItem.toModel()
|
||||
})
|
||||
const items = new Array(Math.max(0, Math.min(length, this.itemCount - start)))
|
||||
.fill(0).map((_, idx) => this.getItem(start + idx))
|
||||
const ret = items.map(e => deepClone(e.toModel()))
|
||||
items.forEach(e => e.clean())
|
||||
return ret
|
||||
}
|
||||
|
||||
slidePage(context: BridgeContext, page: number, smooth = false) {
|
||||
|
16
doric-js/src/widget/utils.ts
Normal file
16
doric-js/src/widget/utils.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { NativeViewModel } from "../ui/view";
|
||||
|
||||
export function deepClone(nativeViewModel: NativeViewModel) {
|
||||
const ret = {
|
||||
id: nativeViewModel.id,
|
||||
type: nativeViewModel.type,
|
||||
props: {
|
||||
...nativeViewModel.props
|
||||
},
|
||||
}
|
||||
if (nativeViewModel.props.subviews) {
|
||||
ret.props.subviews = (nativeViewModel.props.subviews as NativeViewModel[])
|
||||
.map(e => deepClone(e));
|
||||
}
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user