@tarojs/plugin-platform-harmony-ets 4.0.0-beta.5 → 4.0.0-beta.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +4 -0
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/network/request.ts +5 -5
  7. package/dist/apis/route/index.ts +15 -0
  8. package/dist/apis/storage/index.ts +148 -80
  9. package/dist/apis/ui/animation/animation.ts +71 -28
  10. package/dist/apis/ui/background.ts +2 -1
  11. package/dist/apis/ui/interaction/index.ts +40 -49
  12. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  13. package/dist/apis/utils/index.ts +1 -1
  14. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  15. package/dist/apis/wxml/index.ts +2 -0
  16. package/dist/apis/wxml/selectorQuery.ts +18 -9
  17. package/dist/components-harmony-ets/button.ets +48 -34
  18. package/dist/components-harmony-ets/canvas.ets +51 -0
  19. package/dist/components-harmony-ets/checkbox.ets +69 -61
  20. package/dist/components-harmony-ets/form.ets +51 -29
  21. package/dist/components-harmony-ets/icon.ets +31 -19
  22. package/dist/components-harmony-ets/image.ets +27 -14
  23. package/dist/components-harmony-ets/index.ets +85 -0
  24. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  25. package/dist/components-harmony-ets/input.ets +41 -40
  26. package/dist/components-harmony-ets/label.ets +69 -42
  27. package/dist/components-harmony-ets/movableArea.ets +126 -0
  28. package/dist/components-harmony-ets/movableView.ets +73 -0
  29. package/dist/components-harmony-ets/navigationBar.ets +25 -0
  30. package/dist/components-harmony-ets/pageMeta.ets +28 -0
  31. package/dist/components-harmony-ets/picker.ets +42 -38
  32. package/dist/components-harmony-ets/progress.ets +52 -0
  33. package/dist/components-harmony-ets/pseudo.ets +80 -0
  34. package/dist/components-harmony-ets/radio.ets +71 -64
  35. package/dist/components-harmony-ets/richText.ets +14 -30
  36. package/dist/components-harmony-ets/scrollView.ets +61 -57
  37. package/dist/components-harmony-ets/slider.ets +15 -14
  38. package/dist/components-harmony-ets/style.ets +390 -130
  39. package/dist/components-harmony-ets/swiper.ets +38 -20
  40. package/dist/components-harmony-ets/switch.ets +30 -28
  41. package/dist/components-harmony-ets/{index.ts → tag.ts} +2 -0
  42. package/dist/components-harmony-ets/text.ets +121 -51
  43. package/dist/components-harmony-ets/textArea.ets +35 -34
  44. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  45. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  46. package/dist/components-harmony-ets/utils/flexManager.ets +47 -19
  47. package/dist/components-harmony-ets/utils/helper.ets +17 -5
  48. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  49. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  50. package/dist/components-harmony-ets/utils/index.ts +50 -51
  51. package/dist/components-harmony-ets/utils/styles.ets +170 -93
  52. package/dist/components-harmony-ets/video.ets +34 -20
  53. package/dist/components-harmony-ets/view.ets +63 -52
  54. package/dist/components-harmony-ets/webView.ets +40 -34
  55. package/dist/index.d.ts +152 -0
  56. package/dist/index.js +82 -39
  57. package/dist/index.js.map +1 -1
  58. package/dist/runtime-ets/bom/document.ts +6 -4
  59. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  60. package/dist/runtime-ets/bom/window.ts +7 -0
  61. package/dist/runtime-ets/current.ts +3 -0
  62. package/dist/runtime-ets/dom/bind.ts +31 -13
  63. package/dist/runtime-ets/dom/cssNesting.ts +393 -0
  64. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +25 -39
  65. package/dist/runtime-ets/dom/document.ts +22 -8
  66. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  67. package/dist/runtime-ets/dom/element/element.ts +317 -51
  68. package/dist/runtime-ets/dom/element/form.ts +23 -26
  69. package/dist/runtime-ets/dom/element/index.ts +24 -2
  70. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  71. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  72. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  73. package/dist/runtime-ets/dom/element/progress.ts +12 -0
  74. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  75. package/dist/runtime-ets/dom/element/text.ts +1 -8
  76. package/dist/runtime-ets/dom/element/video.ts +5 -3
  77. package/dist/runtime-ets/dom/element/webView.ts +11 -3
  78. package/dist/runtime-ets/dom/event.ts +0 -1
  79. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  80. package/dist/runtime-ets/dom/node.ts +46 -28
  81. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +334 -230
  82. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  83. package/dist/runtime-ets/dom/stylesheet/type.ts +40 -9
  84. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  85. package/dist/runtime-ets/index.ts +2 -2
  86. package/dist/runtime-ets/interface/event.ts +1 -1
  87. package/dist/runtime-ets/utils/index.ts +66 -11
  88. package/dist/runtime-ets/utils/info.ts +1 -1
  89. package/dist/runtime-framework/react/app.ts +7 -2
  90. package/dist/runtime-framework/react/index.ts +0 -2
  91. package/dist/runtime-framework/react/native-page.ts +32 -14
  92. package/dist/runtime-framework/react/page.ts +3 -8
  93. package/dist/runtime-framework/solid/app.ts +25 -45
  94. package/dist/runtime-framework/solid/connect.ts +21 -3
  95. package/dist/runtime-framework/solid/hooks.ts +16 -11
  96. package/dist/runtime-framework/solid/index.ts +6 -2
  97. package/dist/runtime-framework/solid/page.ts +84 -30
  98. package/dist/runtime-framework/solid/reconciler/props.ts +65 -20
  99. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  100. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  101. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  102. package/dist/runtime-utils.d.ts +827 -0
  103. package/dist/runtime-utils.js +399 -188
  104. package/dist/runtime-utils.js.map +1 -1
  105. package/dist/runtime.d.ts +1 -0
  106. package/dist/runtime.js +399 -188
  107. package/dist/runtime.js.map +1 -1
  108. package/index.js +3 -1
  109. package/package.json +13 -13
  110. package/static/media/cancel.svg +1 -1
  111. package/static/media/circle.svg +1 -1
  112. package/static/media/clear.svg +1 -1
  113. package/static/media/download.svg +1 -1
  114. package/static/media/info.svg +1 -1
  115. package/static/media/info_circle.svg +1 -1
  116. package/static/media/search.svg +1 -1
  117. package/static/media/success.svg +1 -1
  118. package/static/media/success_no_circle.svg +1 -1
  119. package/static/media/warn.svg +1 -1
  120. package/types/harmony.d.ts +4 -0
  121. package/types/index.d.ts +4 -0
  122. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,11 +1,14 @@
1
1
  // @ts-nocheck
2
- import matrix4 from '@ohos.matrix4'
2
+ // import matrix4 from '@ohos.matrix4'
3
3
 
4
4
  export interface HarmonyStyle extends TaroStyleType {
5
5
  textAlign?: TextAlign
6
6
  textOverflow?: HarmonyType.Overflow
7
7
  WebkitLineClamp?: number
8
+ whiteSpace?: string
8
9
  letterSpacing?: number | string
10
+ verticalAlign?: Alignment
11
+ lineHeight?: Length
9
12
  }
10
13
 
11
14
  export interface TaroStyleType {
@@ -30,11 +33,14 @@ export interface TaroStyleType {
30
33
  maxWidth?: Length
31
34
 
32
35
  display?: 'flex' | 'block' | 'none'
36
+ visibility?: 'visible' | 'hidden'
33
37
 
34
38
  // position
35
39
  position?: 'relative' | 'absolute' | 'fixed'
36
40
  top?: Length
37
41
  left?: Length
42
+ bottom?: Length
43
+ right?: Length
38
44
 
39
45
  // flex
40
46
  flexBasis?: number | string
@@ -54,6 +60,10 @@ export interface TaroStyleType {
54
60
  backgroundSize?: SizeOptions | ImageSize
55
61
  backgroundPosition?: Position | Alignment
56
62
 
63
+ // 渐变
64
+ linearGradient?: HarmonyType.LinearGradient
65
+ radialGradient?: HarmonyType.RadialGradient
66
+
57
67
  // transform
58
68
  rotate?: HarmonyType.Transform.Rotate
59
69
  translate?: HarmonyType.Transform.Translate
@@ -89,24 +99,36 @@ export interface TaroStyleType {
89
99
  fontStyle?: FontStyle
90
100
  fontWeight?: number | FontWeight | string
91
101
  fontFamily?: string | Resource
92
- lineHeight?: string | number | Resource
93
- textDecoration?: TextDecorationType
102
+ textDecoration?: {
103
+ type: TextDecorationType
104
+ }
94
105
 
95
- // gradient
96
- linearGradient?: HarmonyType.LinearGradient
106
+ // animation
107
+ animationName?: {
108
+ percentage: number
109
+ event: TaroStyleType
110
+ }[]
111
+ animationDuration?: number
112
+ animationTimingFunction?: string
113
+ animationDelay?: number
114
+ animationIterationCount?: number
97
115
 
98
116
  // other
99
117
  opacity?: number | Resource
100
118
  zIndex?: number
101
- overflow?: boolean
119
+ overflow?: string
102
120
  focus?: boolean
121
+ content?: string
103
122
  }
104
123
 
105
124
  export interface TaroTextStyleType {
106
125
  textAlign?: TextAlign
107
126
  textOverflow?: HarmonyType.Overflow
108
127
  WebkitLineClamp?: number
128
+ whiteSpace?: string
109
129
  letterSpacing?: number | string
130
+ verticalAlign?: Alignment
131
+ lineHeight?: string | number | Resource
110
132
  }
111
133
 
112
134
  export namespace HarmonyType {
@@ -121,6 +143,12 @@ export namespace HarmonyType {
121
143
  colors: Array<[ResourceColor, number]>
122
144
  repeating?: boolean
123
145
  }
146
+ export interface RadialGradient {
147
+ center: any
148
+ radius: number | string
149
+ colors: Array<[ResourceColor, number]>
150
+ repeating?: boolean
151
+ }
124
152
  export interface Overflow {
125
153
  overflow: TextOverflow
126
154
  }
@@ -134,7 +162,6 @@ export namespace HarmonyType {
134
162
  export interface backgroundImage {
135
163
  src: ResourceStr
136
164
  repeat?: ImageRepeat
137
- colors?: Array<[ResourceColor, number]>
138
165
  }
139
166
  export type backgroundImageSize = SizeOptions | ImageSize
140
167
  export type backgroundImagePosition = Position | Alignment
@@ -166,7 +193,11 @@ export namespace HarmonyType {
166
193
  centerX?: number | string
167
194
  centerY?: number | string
168
195
  }
169
- export type Transform = matrix4.Matrix4Transit
196
+ // export type Transform = matrix4.Matrix4Transit
197
+ export type Transform = {
198
+ Translate?: Translate
199
+ Scale?: Scale
200
+ Rotate?: Rotate
201
+ }
170
202
  }
171
203
  }
172
-
@@ -1,5 +1,5 @@
1
1
  // @ts-nocheck
2
- import matrix4 from '@ohos.matrix4'
2
+ // import matrix4 from '@ohos.matrix4'
3
3
  import { isNumber } from '@tarojs/shared'
4
4
 
5
5
  import { convertNumber2VP } from '../../'
@@ -163,7 +163,6 @@ export class FlexManager {
163
163
  }
164
164
  }
165
165
 
166
-
167
166
  export class BORDER_STYLE_MAP {
168
167
  static solid = BorderStyle.Solid
169
168
  static dotted = BorderStyle.Dotted
@@ -184,53 +183,53 @@ export class BORDER_STYLE_MAP {
184
183
  case BorderStyle.Solid: return 'solid'
185
184
  default: return ''
186
185
  }
187
-
188
186
  }
189
187
  }
190
188
 
191
-
192
189
  export function getNodeMarginOrPaddingData (dataValue: string) {
193
190
  let res: any = {}
194
191
  if (dataValue) {
195
- const values = dataValue.trim().split(new RegExp('\\s+'))
192
+ const values = dataValue.toString().trim().split(new RegExp('\\s+'))
193
+ let val1: string
194
+ let val2: string
196
195
  switch (values.length) {
197
196
  case 1:
198
- res = { top: values[0], right: values[0], bottom: values[0], left: values[0] }
197
+ val1 = getUnit(values[0])
198
+ res = { top: val1, right: val1, bottom: val1, left: val1 }
199
199
  break
200
200
  case 2:
201
- res = { top: values[0], right: values[1], bottom: values[0], left: values[1] }
201
+ val1 = getUnit(values[0])
202
+ val2 = getUnit(values[1])
203
+ res = { top: val1, right: val2, bottom: val1, left: val2 }
202
204
  break
203
205
  case 3:
204
- res = { top: values[0], right: values[1], bottom: values[2], left: values[1] }
206
+ val2 = getUnit(values[1])
207
+ res = { top: getUnit(values[0]), right: val2, bottom: getUnit(values[2]), left: val2 }
205
208
  break
206
209
  case 4:
207
- res = { top: values[0], right: values[1], bottom: values[2], left: values[3] }
210
+ res = { top: getUnit(values[0]), right: getUnit(values[1]), bottom: getUnit(values[2]), left: getUnit(values[3]) }
208
211
  break
209
212
  default:
210
213
  break
211
214
  }
212
- Object.keys(res).forEach(key => {
213
- res[key] = getUnit(res[key]) || 0
214
- })
215
215
  }
216
216
  return res
217
217
  }
218
218
 
219
-
220
219
  export function getUnit (val) {
221
220
  // 空的字符串代表 Reconciler remove 了这个 prop,不进行后面的逻辑了
222
221
  if (val === '') return val
223
222
 
224
- if (/\d+(vp)$/.test(val)) {
223
+ if (/\d+(vp|px)$/.test(val)) {
225
224
  return val
226
225
  } else if (isNumber(val)) {
227
- return convertNumber2VP(parseFloat(val))
226
+ return parseFloat(val) + 'px'
228
227
  }
229
228
  if (val) {
230
229
  // 匹配vw\vh
231
- const exec = val.match(/(\d+)(vw|vh|px)$/)
230
+ const exec = val.match(/(-?\d*(\.\d+)?)(vw|vh)$/)
232
231
  if (exec) {
233
- const [, num, unit] = exec
232
+ const [, num, , unit] = exec
234
233
  return convertNumber2VP(parseFloat(num), unit)
235
234
  }
236
235
  }
@@ -238,19 +237,26 @@ export function getUnit (val) {
238
237
  }
239
238
 
240
239
  export function getTransform(transform) {
240
+ // if (transform) {
241
+ // return transform.reduce((res, item) => {
242
+ // switch (item.type) {
243
+ // case 'Translate': return res.translate(item.value)
244
+ // case 'Scale': return res.scale(item.value)
245
+ // case 'Rotate': return res.rotate(item.value)
246
+ // case 'Matrix': return res.combine(matrix4.init(item.value))
247
+ // }
248
+ // return res
249
+ // }, matrix4.identity())
250
+ // }
251
+ const result = {}
241
252
  if (transform) {
242
- return transform.reduce((res, item) => {
243
- switch (item.type) {
244
- case 'Translate': return res.translate(item.value)
245
- case 'Scale': return res.scale(item.value)
246
- case 'Rotate': return res.rotate(item.value)
247
- case 'Matrix': return res.combine(matrix4.init(item.value))
248
- }
249
- return res
250
- }, matrix4.identity())
253
+ transform.forEach((item) => {
254
+ result[item.type] = item.value
255
+ })
256
+ return result
251
257
  }
252
258
  }
253
259
 
254
260
  export function capitalizeFirstLetter (str: string) {
255
261
  return str.charAt(0).toUpperCase() + str.slice(1)
256
- }
262
+ }
@@ -10,9 +10,9 @@ export * from './dom/element'
10
10
  export * from './dom/event'
11
11
  export * from './dom/node'
12
12
  export * from './dom/stylesheet'
13
+ export * from './dom/cssNesting'
13
14
  export * from './interface'
14
15
  export * from './utils'
15
- export * from './utils/bind'
16
16
  export * from './utils/info'
17
- export { URLSearchParams, eventSource } from '@tarojs/runtime/dist/runtime.esm'
17
+ export { URL, URLSearchParams, eventSource, Events } from '@tarojs/runtime/dist/runtime.esm'
18
18
  export { hooks } from '@tarojs/shared'
@@ -7,4 +7,4 @@ export interface EventOptions {
7
7
  export interface EventHandler<T = any, R = void> {
8
8
  (...args: T[]): R
9
9
  _stop?: boolean
10
- }
10
+ }
@@ -1,5 +1,5 @@
1
1
  import _display from '@ohos.display'
2
- import { pxTransformHelper } from '@tarojs/taro'
2
+ import { getSystemInfoSync, pxTransformHelper } from '@tarojs/taro'
3
3
 
4
4
  import { NodeType } from '../dom/node'
5
5
  import convertWebStyle2HmStyle from '../dom/stylesheet/covertWeb2Hm'
@@ -38,28 +38,80 @@ export function convertNumber2PX (value: number) {
38
38
  return pxTransformHelper(value, 'vp')
39
39
  }
40
40
 
41
- export function convertNumber2VP (value: number, unit = 'px') {
41
+ export function convertNumber2VP (value: number, unit = 'px'): string | number {
42
42
  if (unit === 'vw' || unit === 'vh') {
43
43
  return (value / 100 * (unit === 'vw' ? display.width: display.height)) + 'px'
44
44
  }
45
+ if (unit === 'PX') {
46
+ // 特殊单位:相当于PX、pX、Px
47
+ return pxTransformHelper(value, 'PX')
48
+ }
45
49
  return pxTransformHelper(value, 'vp')
46
50
  }
47
51
 
48
- export function calcDynamicStyle (styleSheet: Record<string, CSSProperties>, classNames: string, style: CSSProperties): CSSProperties {
52
+ export function parseClasses (classNames = ''): string[] {
53
+ return classNames.includes(' ') ? classNames.split(' ') : [classNames]
54
+ }
55
+
56
+ // 合并静态样式,从样式表里面找到对应的样式
57
+ export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames = ''): CSSProperties {
49
58
  const obj: CSSProperties[] = []
50
- const classes = typeof classNames === 'string' ? classNames.split(' ') : []
51
- for (let i = 0; i < classes.length; i++) {
52
- const className = classes[i]
53
- if (styleSheet[className]) {
54
- obj.push(styleSheet[className])
59
+
60
+ if (!styleSheet.cache) {
61
+ styleSheet.cache = {}
62
+ }
63
+ const cache: Record<string, CSSProperties> = styleSheet.cache as Record<string, CSSProperties>
64
+
65
+ const classes = parseClasses(classNames)
66
+ if (classes.length === 1) {
67
+ // 同一个引用
68
+ return styleSheet[classes[0]]
69
+ } else {
70
+ if (cache[classNames]) {
71
+ return cache[classNames]
72
+ } else {
73
+ for (let i = 0; i < classes.length; i++) {
74
+ const className = classes[i]
75
+ if (styleSheet[className]) {
76
+ obj.push(styleSheet[className])
77
+ }
78
+ }
79
+ const result = Object.assign.apply(null, [{}].concat(obj))
80
+
81
+ cache[classNames] = result
82
+
83
+ return result
55
84
  }
56
85
  }
86
+ }
57
87
 
88
+ // 动态样式计算,需要经过web2harmony进行反转
89
+ export function calcDynamicStyle (style: CSSProperties): CSSProperties {
58
90
  if (style) {
59
- obj.push(convertWebStyle2HmStyle(style))
91
+ return convertWebStyle2HmStyle(style)
60
92
  }
93
+ return {}
94
+ }
95
+
96
+ // css env()环境样式获取
97
+ export function __env__(safeAreaType: string, fallback?: string | number) {
98
+ const sysInfo = getSystemInfoSync()
61
99
 
62
- return Object.assign.apply(null, [{}].concat(obj))
100
+ switch (safeAreaType) {
101
+ case 'safe-area-inset-top': {
102
+ return sysInfo.safeArea?.top ? `${sysInfo.safeArea?.top}px` : fallback
103
+ }
104
+ case 'safe-area-inset-right': {
105
+ return sysInfo.safeArea?.right ? `${sysInfo.screenWidth - sysInfo.safeArea?.right}px` : fallback
106
+ }
107
+ case 'safe-area-inset-bottom': {
108
+ return sysInfo.safeArea?.bottom ? `${sysInfo.screenHeight - sysInfo.safeArea?.bottom}px` : fallback
109
+ }
110
+ case 'safe-area-inset-left': {
111
+ return sysInfo.safeArea?.left ? `${sysInfo.safeArea?.left}px` : fallback
112
+ }
113
+ }
114
+ return fallback
63
115
  }
64
116
 
65
117
  export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
@@ -76,6 +128,10 @@ export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
76
128
  return scrollerOrNode
77
129
  }
78
130
 
131
+ export function ObjectKeys(obj: object): string[] {
132
+ return Object.keys(obj)
133
+ }
134
+
79
135
  export function ObjectAssign(...objects) {
80
136
  return Object.assign.apply(this, [{}].concat(...objects))
81
137
  }
@@ -91,7 +147,6 @@ export function bindFn (fn: any, ctx: any, ...args: any) {
91
147
  }
92
148
  }
93
149
 
94
-
95
150
  // 使用深度优先遍历寻找节点树中对应的子节点,且只需要找到第一个
96
151
  // 通过 selector 判断是 id 还是 selector,从 node 的 id 和 className 属性中寻找
97
152
  export function findChildNodeWithDFS<T extends TaroElement = TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll: true): T[] | null;
@@ -50,7 +50,7 @@ function tapCallbackToNodeAndUpdate (node: TaroElement, eventName: string, callb
50
50
  callback && callback(...eventResult)
51
51
  }
52
52
 
53
- if (!node._isDynamicNode || !node._isCompileMode) {
53
+ if (!node._isDynamicNode && node._isCompileMode) {
54
54
  node.updateComponent()
55
55
  }
56
56
  }
@@ -1,10 +1,11 @@
1
1
  import { Current, document } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
- import { AppInstance, eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
2
+ import { eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
3
3
 
4
4
  import { setReconciler } from './connect'
5
5
  import { injectPageInstance } from './page'
6
6
  import { EMPTY_OBJ, incrementId, isClassComponent } from './utils'
7
7
 
8
+ import type { AppInstance } from '@tarojs/runtime'
8
9
  import type React from 'react'
9
10
 
10
11
  let h: typeof React.createElement
@@ -237,7 +238,11 @@ export function createReactApp (
237
238
  }
238
239
  } as unknown as AppInstance
239
240
 
240
- Current.app = app
241
+ if (Current.app) {
242
+ Current.app = Object.assign(app, Current.app)
243
+ } else {
244
+ Current.app = app
245
+ }
241
246
 
242
247
  return app
243
248
  }
@@ -2,8 +2,6 @@ import { hooks } from '@tarojs/shared'
2
2
 
3
3
  import * as taroHooks from './hooks'
4
4
 
5
- // declare const __TARO_FRAMEWORK__: string;
6
-
7
5
  hooks.tap('initNativeApi', function (taro) {
8
6
  for (const hook in taroHooks) {
9
7
  taro[hook] = taroHooks[hook]
@@ -1,15 +1,14 @@
1
1
  import { Current, document, requestAnimationFrame, TaroElement, window } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
- import { CONTEXT_ACTIONS, env, eventCenter, TFunc } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
2
+ import { addLeadingSlash, CONTEXT_ACTIONS, env, eventCenter, TFunc } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
3
3
  import { ensure, hooks, isUndefined } from '@tarojs/shared'
4
4
 
5
5
  import { ReactMeta as reactMeta } from './app'
6
6
  import { setReconciler } from './connect'
7
7
  import { ON_HIDE, ON_READY, ON_SHOW } from './constant'
8
8
  import {
9
- addLeadingSlash,
10
9
  getOnHideEventKey,
11
10
  getOnReadyEventKey,
12
- getOnShowEventKey,
11
+ getOnShowEventKey,
13
12
  getPath,
14
13
  injectPageInstance,
15
14
  removePageInstance,
@@ -53,10 +52,16 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
53
52
 
54
53
  componentDidMount () {
55
54
  this.ctx.component = this
56
- const rootElement = this.root.current!
57
- rootElement.ctx = this.ctx
58
- // TODO: performUpdate
59
- // rootElement.performUpdate(true)
55
+ if (this.root.current) {
56
+ this.root.current = this.ctx
57
+ }
58
+ }
59
+
60
+ // React 16 uncaught error 会导致整个应用 crash,
61
+ // 目前把错误缩小到页面
62
+ componentDidCatch (error, info: React.ErrorInfo) {
63
+ console.warn(error)
64
+ console.error(info.componentStack)
60
65
  }
61
66
 
62
67
  render () {
@@ -80,13 +85,24 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
80
85
 
81
86
  componentDidMount () {
82
87
  if (isDefaultEntryDom) {
83
- Current.app = this
88
+ if (Current.app) {
89
+ Current.app = Object.assign(this, Current.app)
90
+ } else {
91
+ Current.app = this
92
+ }
84
93
  } else {
85
94
  nativeComponentApp = this
86
95
  }
87
96
  cb && cb()
88
97
  }
89
98
 
99
+ // React 16 uncaught error 会导致整个应用 crash,
100
+ // 目前把错误缩小到页面
101
+ componentDidCatch (error, info: React.ErrorInfo) {
102
+ console.warn(error)
103
+ console.error(info.componentStack)
104
+ }
105
+
90
106
  mount (Component, compId, getCtx, cb?) {
91
107
  const isReactComponent = isClassComponent(R, Component)
92
108
  const inject = (node?: any) => node && injectPageInstance(node, compId)
@@ -153,7 +169,7 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
153
169
  // create
154
170
  const nativeApp = document.createElement('nativeComponent')
155
171
  // insert
156
- app.appendChild(nativeApp)
172
+ app?.appendChild(nativeApp)
157
173
  app = nativeApp
158
174
  }
159
175
  // eslint-disable-next-line react/no-deprecated
@@ -253,7 +269,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
253
269
  window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
254
270
  // 触发onUnload生命周期
255
271
  safeExecute($taroPath, ONUNLOAD)
256
- resetCurrent()
272
+ resetCurrent.call(this)
257
273
  unmounting = true
258
274
  Current.app!.unmount!($taroPath, () => {
259
275
  unmounting = false
@@ -274,6 +290,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
274
290
  safeExecute(this.$taroPath, ON_READY)
275
291
  // 通过事件触发子组件的生命周期
276
292
  requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
293
+ this.onReady = {}
277
294
  this.onReady.called = true
278
295
  })
279
296
  },
@@ -306,12 +323,13 @@ export function createNativePageConfig (Component, pageName: string, react: type
306
323
  }
307
324
 
308
325
  function resetCurrent () {
309
- // 小程序插件页面卸载之后返回到宿主页面时,需重置Current页面和路由。否则引发插件组件二次加载异常 fix:#11991
310
- Current.page = null
311
- Current.router = null
326
+ if (Current.page === this) {
327
+ // 小程序插件页面卸载之后返回到宿主页面时,需重置Current页面和路由。否则引发插件组件二次加载异常 fix:#11991
328
+ Current.page = null
329
+ Current.router = null
330
+ }
312
331
  }
313
332
 
314
-
315
333
  LIFECYCLES.forEach((lifecycle) => {
316
334
  pageObj[lifecycle] = function () {
317
335
  return safeExecute(this.$taroPath, lifecycle, ...arguments)
@@ -1,5 +1,5 @@
1
1
  import { Current, document, requestAnimationFrame, window } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
- import { CONTEXT_ACTIONS, env, eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
2
+ import { addLeadingSlash, CONTEXT_ACTIONS, env, eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
3
3
  import { hooks, isArray, isFunction, isUndefined } from '@tarojs/shared'
4
4
 
5
5
  import { ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, ON_UNLOAD } from './constant'
@@ -23,13 +23,6 @@ export function removePageInstance (id: string) {
23
23
  instances.delete(id)
24
24
  }
25
25
 
26
- export function addLeadingSlash (path?: string): string {
27
- if (path == null) {
28
- return ''
29
- }
30
- return path.charAt(0) === '/' ? path : '/' + path
31
- }
32
-
33
26
  export function safeExecute (path: string, lifecycle: string, ...args: unknown[]) {
34
27
  const instance = instances.get(path)
35
28
 
@@ -184,6 +177,8 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
184
177
  safeExecute(this.$taroPath, ON_READY)
185
178
  // 通过事件触发子组件的生命周期
186
179
  requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
180
+ this.onReady = {}
181
+ this.onReady.called = true
187
182
  })
188
183
  },
189
184
  [ONSHOW] (options = {}) {