@@ -33,14 +33,13 @@ export class TaroElement<
33
33
> extends TaroNode {
34
34
public _innerHTML = ''
35
35
public _nodeInfo : TaroAny = {
36
- layer : 0 // 渲染层级
36
+ layer : 0 , // 渲染层级
37
37
}
38
38
39
39
public _hm_instance : TaroAny
40
40
public weak_hm_instance : WeakRef < TaroAny >
41
41
public use_weak_hm_instance : boolean = true
42
42
43
-
44
43
public get hm_instance ( ) : TaroAny {
45
44
if ( this . use_weak_hm_instance && this . weak_hm_instance ) {
46
45
return this . weak_hm_instance ?. deref ( )
@@ -56,17 +55,16 @@ export class TaroElement<
56
55
this . _hm_instance = instance
57
56
}
58
57
59
-
60
- public get _instance ( ) {
58
+ public get _instance ( ) {
61
59
return this . hm_instance
62
60
}
63
61
64
- public set _instance ( value ) {
62
+ public set _instance ( value ) {
65
63
this . hm_instance = value
66
64
if ( this . _nodeInfo . aboutToAppear ) {
67
65
let task
68
66
// eslint-disable-next-line no-cond-assign
69
- while ( task = this . _nodeInfo . aboutToAppear . shift ( ) ) {
67
+ while ( ( task = this . _nodeInfo . aboutToAppear . shift ( ) ) ) {
70
68
task ( )
71
69
}
72
70
}
@@ -144,6 +142,10 @@ export class TaroElement<
144
142
145
143
// 混合开发的组件没办法自动更新,需要把父级的结点删掉新建
146
144
// Current.nativeComponentNames会在render.ets中赋值
145
+ /**
146
+ * @deprecated
147
+ * 这个逻辑分支在多线程中需要要去掉
148
+ */
147
149
if ( Current . nativeComponentNames ?. includes ( this . tagName ) ) {
148
150
const idxOfRef = this . parentNode ?. findIndex ( this )
149
151
@@ -159,7 +161,7 @@ export class TaroElement<
159
161
id : this . _nid ,
160
162
tagName : this . tagName ,
161
163
attribute : name ,
162
- value
164
+ value,
163
165
} )
164
166
} else {
165
167
const attributeTriggerValue : TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP [ name ]
@@ -266,7 +268,7 @@ export class TaroElement<
266
268
if ( ! this . _pseudo_before ) {
267
269
this . _pseudo_before = new StyleSheet ( )
268
270
}
269
- Object . keys ( value ) . forEach ( key => {
271
+ Object . keys ( value ) . forEach ( ( key ) => {
270
272
this . _pseudo_before ! . hmStyle [ key ] = value [ key ]
271
273
} )
272
274
} else {
@@ -281,7 +283,7 @@ export class TaroElement<
281
283
if ( ! this . _pseudo_after ) {
282
284
this . _pseudo_after = new StyleSheet ( )
283
285
}
284
- Object . keys ( value ) . forEach ( key => {
286
+ Object . keys ( value ) . forEach ( ( key ) => {
285
287
this . _pseudo_after ! . hmStyle [ key ] = value [ key ]
286
288
} )
287
289
} else {
@@ -299,15 +301,15 @@ export class TaroElement<
299
301
if ( ! this . _pseudo_class [ name ] ) {
300
302
this . _pseudo_class [ name ] = new StyleSheet ( )
301
303
}
302
- Object . keys ( value ) . forEach ( key => {
304
+ Object . keys ( value ) . forEach ( ( key ) => {
303
305
this . _pseudo_class [ name ] ! . hmStyle [ key ] = value [ key ]
304
306
} )
305
307
} else {
306
308
this . _pseudo_class [ name ] = null
307
309
}
308
310
}
309
311
310
- get currentLayerNode ( ) {
312
+ get currentLayerNode ( ) {
311
313
if ( ! this . _page ) return null
312
314
if ( typeof this . _page . tabBarCurrentIndex !== 'undefined' ) {
313
315
this . _page . layerNode ||= [ ]
@@ -320,7 +322,7 @@ export class TaroElement<
320
322
}
321
323
}
322
324
323
- get currentLayerParents ( ) {
325
+ get currentLayerParents ( ) {
324
326
if ( ! this . _page ) return null
325
327
if ( typeof this . _page . tabBarCurrentIndex !== 'undefined' ) {
326
328
this . _page . layerParents ||= { }
@@ -337,7 +339,7 @@ export class TaroElement<
337
339
// 1、appendChild的时候会判断是否需要设置层级
338
340
// 2、taro-react的setProperty,在处理属性变化的时候,会判断是否需要设置层级
339
341
// 3、removeChild的时候,会判断是否需要移除层级
340
- public setLayer ( value : number ) {
342
+ public setLayer ( value : number ) {
341
343
if ( ! this . parentNode ) return // 没有父节点,不需要设置层级关系
342
344
343
345
const currentPage = getPageById ( this . getAttribute ( '__fixed' ) )
@@ -359,7 +361,7 @@ export class TaroElement<
359
361
generateLayerParentIds ( _parentRecord , this )
360
362
currentLayerParents [ this . getStrNid ( ) ] = _parentRecord
361
363
} else {
362
- const idx = currentLayerNode . childNodes . findIndex ( n => n . getStrNid ( ) === this . getStrNid ( ) )
364
+ const idx = currentLayerNode . childNodes . findIndex ( ( n ) => n . getStrNid ( ) === this . getStrNid ( ) )
363
365
currentLayerNode . childNodes . splice ( idx , 1 )
364
366
currentLayerNode . notifyDataDelete ( idx )
365
367
@@ -385,7 +387,7 @@ export class TaroElement<
385
387
delete currentLayerParents [ this . getStrNid ( ) ]
386
388
this . setLayer ( 0 )
387
389
} else {
388
- Object . keys ( currentLayerParents ) . forEach ( fixedId => {
390
+ Object . keys ( currentLayerParents ) . forEach ( ( fixedId ) => {
389
391
const parentIds = currentLayerParents [ fixedId ]
390
392
if ( parentIds [ this . getStrNid ( ) ] ) {
391
393
// 需要移除fixedId
@@ -401,7 +403,7 @@ export class TaroElement<
401
403
}
402
404
403
405
// 设置动画
404
- public setAnimation ( playing ) {
406
+ public setAnimation ( playing ) {
405
407
if ( ! this . _instance ) {
406
408
if ( ! this . _nodeInfo . aboutToAppear ) {
407
409
this . _nodeInfo . aboutToAppear = [ ]
@@ -436,41 +438,50 @@ export class TaroElement<
436
438
this . parentNode . notifyDataDelete ( idx )
437
439
438
440
// 下一帧播放,等实例被移除掉,再重新插入
439
- setTimeout ( ( ) => {
440
- // insert
441
- this . parentNode ?. childNodes . splice ( idx , 0 , this )
442
- this . parentNode ?. notifyDataAdd ( idx )
443
-
444
- // 执行动画
445
- if ( playing ) {
446
- this . playAnimation ( )
447
- }
448
- } , playing ? 0 : 100 )
441
+ setTimeout (
442
+ ( ) => {
443
+ // insert
444
+ this . parentNode ?. childNodes . splice ( idx , 0 , this )
445
+ this . parentNode ?. notifyDataAdd ( idx )
446
+
447
+ // 执行动画
448
+ if ( playing ) {
449
+ this . playAnimation ( )
450
+ }
451
+ } ,
452
+ playing ? 0 : 100
453
+ )
449
454
}
450
455
}
451
456
452
- private playAnimation ( ) {
457
+ private playAnimation ( ) {
453
458
const {
454
- animationDuration = 0 , animationDelay = 0 , animationIterationCount = 1 , animationName : keyframes ,
455
- animationTimingFunction
459
+ animationDuration = 0 ,
460
+ animationDelay = 0 ,
461
+ animationIterationCount = 1 ,
462
+ animationName : keyframes ,
463
+ animationTimingFunction,
456
464
} = this . _st . hmStyle
457
465
458
466
if ( keyframes ) {
459
467
let cur_percentage = 0
460
- this . _instance . getUIContext ( ) ?. keyframeAnimateTo ( {
461
- delay : animationDelay ,
462
- iterations : animationIterationCount ,
463
- } , keyframes . map ( item => {
464
- const duration = ( item . percentage - cur_percentage ) * animationDuration
465
- cur_percentage = item . percentage
466
- return {
467
- duration : duration ,
468
- curve : item . event . animationTimingFunction || animationTimingFunction ,
469
- event : ( ) => {
470
- this . _instance . overwriteStyle = item . event
468
+ this . _instance . getUIContext ( ) ?. keyframeAnimateTo (
469
+ {
470
+ delay : animationDelay ,
471
+ iterations : animationIterationCount ,
472
+ } ,
473
+ keyframes . map ( ( item ) => {
474
+ const duration = ( item . percentage - cur_percentage ) * animationDuration
475
+ cur_percentage = item . percentage
476
+ return {
477
+ duration : duration ,
478
+ curve : item . event . animationTimingFunction || animationTimingFunction ,
479
+ event : ( ) => {
480
+ this . _instance . overwriteStyle = item . event
481
+ } ,
471
482
}
472
- }
473
- } ) )
483
+ } )
484
+ )
474
485
}
475
486
}
476
487
}
0 commit comments