@mpxjs/webpack-plugin 2.10.6 → 2.10.7-beta.10
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.
- package/lib/dependencies/RecordPageConfigsMapDependency.js +1 -1
- package/lib/index.js +71 -51
- package/lib/parser.js +1 -1
- package/lib/platform/json/wx/index.js +0 -1
- package/lib/platform/style/wx/index.js +7 -0
- package/lib/platform/template/wx/component-config/button.js +1 -1
- package/lib/platform/template/wx/component-config/index.js +5 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/movable-view.js +1 -10
- package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
- package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
- package/lib/react/processJSON.js +2 -1
- package/lib/runtime/components/react/AsyncContainer.tsx +189 -0
- package/lib/runtime/components/react/context.ts +23 -4
- package/lib/runtime/components/react/dist/AsyncContainer.jsx +141 -0
- package/lib/runtime/components/react/dist/context.js +5 -2
- package/lib/runtime/components/react/dist/mpx-button.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-input.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +64 -10
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +358 -98
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +3 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +31 -15
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +117 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +53 -27
- package/lib/runtime/components/react/dist/mpx-view.jsx +21 -7
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +13 -13
- package/lib/runtime/components/react/dist/utils.jsx +94 -1
- package/lib/runtime/components/react/mpx-button.tsx +3 -2
- package/lib/runtime/components/react/mpx-input.tsx +1 -1
- package/lib/runtime/components/react/mpx-movable-area.tsx +99 -12
- package/lib/runtime/components/react/mpx-movable-view.tsx +413 -100
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +3 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +84 -59
- package/lib/runtime/components/react/mpx-sticky-header.tsx +181 -0
- package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper.tsx +53 -25
- package/lib/runtime/components/react/mpx-view.tsx +20 -7
- package/lib/runtime/components/react/mpx-web-view.tsx +12 -12
- package/lib/runtime/components/react/utils.tsx +93 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +18 -4
- package/lib/runtime/components/web/mpx-sticky-header.vue +99 -0
- package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
- package/lib/runtime/optionProcessor.js +0 -2
- package/lib/script-setup-compiler/index.js +27 -5
- package/lib/template-compiler/bind-this.js +2 -1
- package/lib/template-compiler/compiler.js +4 -3
- package/package.json +4 -4
- package/LICENSE +0 -433
package/lib/index.js
CHANGED
|
@@ -1815,72 +1815,92 @@ try {
|
|
|
1815
1815
|
normalModuleFactory.hooks.afterResolve.tap('MpxWebpackPlugin', ({ createData }) => {
|
|
1816
1816
|
const { queryObj } = parseRequest(createData.request)
|
|
1817
1817
|
const loaders = createData.loaders
|
|
1818
|
-
|
|
1819
|
-
|
|
1818
|
+
const type = queryObj.type
|
|
1819
|
+
const mpxProcessFlag = queryObj.mpx && queryObj.mpx !== MPX_PROCESSED_FLAG
|
|
1820
|
+
const vueProcessFlag = queryObj.vue && queryObj.mpx !== MPX_PROCESSED_FLAG
|
|
1821
|
+
if (mpxProcessFlag || vueProcessFlag) {
|
|
1820
1822
|
const extract = queryObj.extract
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1823
|
+
if (type === 'styles' || type === 'style') {
|
|
1824
|
+
const loaderTypes = {
|
|
1825
|
+
'node_modules/stylus-loader': -1,
|
|
1826
|
+
'node_modules/sass-loader': -1,
|
|
1827
|
+
'node_modules/less-loader': -1,
|
|
1828
|
+
'node_modules/css-loader': -1
|
|
1829
|
+
}
|
|
1825
1830
|
loaders.forEach((loader, index) => {
|
|
1826
1831
|
const currentLoader = toPosix(loader.loader)
|
|
1827
|
-
|
|
1828
|
-
|
|
1832
|
+
for (const key in loaderTypes) {
|
|
1833
|
+
if (currentLoader.includes(key)) {
|
|
1834
|
+
loaderTypes[key] = index
|
|
1835
|
+
break
|
|
1836
|
+
}
|
|
1829
1837
|
}
|
|
1830
1838
|
})
|
|
1839
|
+
const insertStripLoaders = (index) => {
|
|
1840
|
+
if (index !== -1) {
|
|
1841
|
+
loaders.splice(index, 0, { loader: styleStripConditionalPath, options: {id: 0} })
|
|
1842
|
+
loaders.splice(index + 2, 0, { loader: styleStripConditionalPath, options: {id: 1} })
|
|
1843
|
+
return true
|
|
1844
|
+
}
|
|
1845
|
+
return false
|
|
1846
|
+
}
|
|
1831
1847
|
|
|
1832
|
-
|
|
1833
|
-
|
|
1848
|
+
const priorities = ['node_modules/stylus-loader', 'node_modules/less-loader', 'node_modules/sass-loader', 'node_modules/css-loader']
|
|
1849
|
+
for (const loaderKey of priorities) {
|
|
1850
|
+
if (insertStripLoaders(loaderTypes[loaderKey])) {
|
|
1851
|
+
break
|
|
1852
|
+
}
|
|
1834
1853
|
}
|
|
1835
|
-
loaders.push({ loader: styleStripConditionalPath })
|
|
1836
1854
|
}
|
|
1837
1855
|
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
if (insertBeforeIndex > -1) {
|
|
1853
|
-
loaders.splice(insertBeforeIndex + 1, 0, {
|
|
1854
|
-
loader: info[2]
|
|
1856
|
+
if (mpxProcessFlag) {
|
|
1857
|
+
switch (type) {
|
|
1858
|
+
case 'styles':
|
|
1859
|
+
case 'template': {
|
|
1860
|
+
let insertBeforeIndex = -1
|
|
1861
|
+
const info = typeLoaderProcessInfo[type]
|
|
1862
|
+
loaders.forEach((loader, index) => {
|
|
1863
|
+
const currentLoader = toPosix(loader.loader)
|
|
1864
|
+
if (currentLoader.includes(info[0])) {
|
|
1865
|
+
loader.loader = info[1]
|
|
1866
|
+
insertBeforeIndex = index
|
|
1867
|
+
} else if (currentLoader.includes(info[1])) {
|
|
1868
|
+
insertBeforeIndex = index
|
|
1869
|
+
}
|
|
1855
1870
|
})
|
|
1871
|
+
if (insertBeforeIndex > -1) {
|
|
1872
|
+
loaders.splice(insertBeforeIndex + 1, 0, {
|
|
1873
|
+
loader: info[2]
|
|
1874
|
+
})
|
|
1875
|
+
}
|
|
1876
|
+
break
|
|
1856
1877
|
}
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1878
|
+
case 'json':
|
|
1879
|
+
if (queryObj.isTheme) {
|
|
1880
|
+
loaders.unshift({
|
|
1881
|
+
loader: jsonThemeCompilerPath
|
|
1882
|
+
})
|
|
1883
|
+
} else if (queryObj.isPlugin) {
|
|
1884
|
+
loaders.unshift({
|
|
1885
|
+
loader: jsonPluginCompilerPath
|
|
1886
|
+
})
|
|
1887
|
+
} else {
|
|
1888
|
+
loaders.unshift({
|
|
1889
|
+
loader: jsonCompilerPath
|
|
1890
|
+
})
|
|
1891
|
+
}
|
|
1892
|
+
break
|
|
1893
|
+
case 'wxs':
|
|
1869
1894
|
loaders.unshift({
|
|
1870
|
-
loader:
|
|
1895
|
+
loader: wxsLoaderPath
|
|
1871
1896
|
})
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1897
|
+
break
|
|
1898
|
+
}
|
|
1899
|
+
if (extract) {
|
|
1875
1900
|
loaders.unshift({
|
|
1876
|
-
loader:
|
|
1901
|
+
loader: extractorPath
|
|
1877
1902
|
})
|
|
1878
|
-
|
|
1879
|
-
}
|
|
1880
|
-
if (extract) {
|
|
1881
|
-
loaders.unshift({
|
|
1882
|
-
loader: extractorPath
|
|
1883
|
-
})
|
|
1903
|
+
}
|
|
1884
1904
|
}
|
|
1885
1905
|
createData.resource = addQuery(createData.resource, { mpx: MPX_PROCESSED_FLAG }, true)
|
|
1886
1906
|
}
|
package/lib/parser.js
CHANGED
|
@@ -285,6 +285,13 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
285
285
|
|
|
286
286
|
// line-height
|
|
287
287
|
const formatLineHeight = ({ prop, value, selector }) => {
|
|
288
|
+
// line-height 0 直接返回
|
|
289
|
+
if (+value === 0) {
|
|
290
|
+
return {
|
|
291
|
+
prop,
|
|
292
|
+
value
|
|
293
|
+
}
|
|
294
|
+
}
|
|
288
295
|
return verifyValues({ prop, value, selector }) && ({
|
|
289
296
|
prop,
|
|
290
297
|
value: /^\s*(-?(\d+(\.\d+)?|\.\d+))\s*$/.test(value) ? `${Math.round(value * 100)}%` : value
|
|
@@ -124,7 +124,7 @@ module.exports = function ({ print }) {
|
|
|
124
124
|
if (isMustache(value)) {
|
|
125
125
|
ttValueLog({ name, value })
|
|
126
126
|
} else {
|
|
127
|
-
const supportList = ['share', 'getPhoneNumber', 'contact', 'im', 'openSetting']
|
|
127
|
+
const supportList = ['share', 'getPhoneNumber', 'contact', 'im', 'openSetting', 'addShortcut']
|
|
128
128
|
if (value && supportList.indexOf(value) === -1) {
|
|
129
129
|
ttValueLogError({ name, value })
|
|
130
130
|
}
|
|
@@ -42,6 +42,8 @@ const wxs = require('./wxs')
|
|
|
42
42
|
const component = require('./component')
|
|
43
43
|
const fixComponentName = require('./fix-component-name')
|
|
44
44
|
const rootPortal = require('./root-portal')
|
|
45
|
+
const stickyHeader = require('./sticky-header')
|
|
46
|
+
const stickySection = require('./sticky-section')
|
|
45
47
|
|
|
46
48
|
module.exports = function getComponentConfigs ({ warn, error }) {
|
|
47
49
|
/**
|
|
@@ -125,6 +127,8 @@ module.exports = function getComponentConfigs ({ warn, error }) {
|
|
|
125
127
|
hyphenTagName({ print }),
|
|
126
128
|
label({ print }),
|
|
127
129
|
component(),
|
|
128
|
-
rootPortal({ print })
|
|
130
|
+
rootPortal({ print }),
|
|
131
|
+
stickyHeader({ print }),
|
|
132
|
+
stickySection({ print })
|
|
129
133
|
]
|
|
130
134
|
}
|
|
@@ -51,7 +51,7 @@ module.exports = function ({ print }) {
|
|
|
51
51
|
swan: baiduPropLog
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
|
-
test: /^(
|
|
54
|
+
test: /^(auto-focus|confirm-type|confirm-hold|adjust-position|hold-keyboard)$/,
|
|
55
55
|
tt: ttPropLog
|
|
56
56
|
},
|
|
57
57
|
{
|
|
@@ -2,9 +2,6 @@ const TAG_NAME = 'movable-view'
|
|
|
2
2
|
|
|
3
3
|
module.exports = function ({ print }) {
|
|
4
4
|
const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' })
|
|
5
|
-
const androidEventLog = print({ platform: 'android', tag: TAG_NAME, isError: false, type: 'event' })
|
|
6
|
-
const harmonyEventLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false, type: 'event' })
|
|
7
|
-
const iosEventLog = print({ platform: 'ios', tag: TAG_NAME, isError: false, type: 'event' })
|
|
8
5
|
const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })
|
|
9
6
|
const androidPropLog = print({ platform: 'android', tag: TAG_NAME, isError: false })
|
|
10
7
|
const harmonyPropLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false })
|
|
@@ -36,7 +33,7 @@ module.exports = function ({ print }) {
|
|
|
36
33
|
harmony: harmonyPropLog
|
|
37
34
|
},
|
|
38
35
|
{
|
|
39
|
-
test: /^(damping|friction
|
|
36
|
+
test: /^(damping|friction)$/,
|
|
40
37
|
ios: iosPropLog,
|
|
41
38
|
android: androidPropLog,
|
|
42
39
|
harmony: harmonyPropLog
|
|
@@ -46,12 +43,6 @@ module.exports = function ({ print }) {
|
|
|
46
43
|
{
|
|
47
44
|
test: /^(htouchmove|vtouchmove)$/,
|
|
48
45
|
ali: aliEventLog
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
test: /^(bindscale)$/,
|
|
52
|
-
ios: iosEventLog,
|
|
53
|
-
android: androidEventLog,
|
|
54
|
-
harmony: harmonyEventLog
|
|
55
46
|
}
|
|
56
47
|
]
|
|
57
48
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const TAG_NAME = 'sticky-header'
|
|
2
|
+
|
|
3
|
+
module.exports = function ({ print }) {
|
|
4
|
+
return {
|
|
5
|
+
test: TAG_NAME,
|
|
6
|
+
android (tag, { el }) {
|
|
7
|
+
el.isBuiltIn = true
|
|
8
|
+
return 'mpx-sticky-header'
|
|
9
|
+
},
|
|
10
|
+
ios (tag, { el }) {
|
|
11
|
+
el.isBuiltIn = true
|
|
12
|
+
return 'mpx-sticky-header'
|
|
13
|
+
},
|
|
14
|
+
harmony (tag, { el }) {
|
|
15
|
+
el.isBuiltIn = true
|
|
16
|
+
return 'mpx-sticky-header'
|
|
17
|
+
},
|
|
18
|
+
web (tag, { el }) {
|
|
19
|
+
el.isBuiltIn = true
|
|
20
|
+
return 'mpx-sticky-header'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const TAG_NAME = 'sticky-section'
|
|
2
|
+
|
|
3
|
+
module.exports = function ({ print }) {
|
|
4
|
+
return {
|
|
5
|
+
test: TAG_NAME,
|
|
6
|
+
android (tag, { el }) {
|
|
7
|
+
el.isBuiltIn = true
|
|
8
|
+
return 'mpx-sticky-section'
|
|
9
|
+
},
|
|
10
|
+
ios (tag, { el }) {
|
|
11
|
+
el.isBuiltIn = true
|
|
12
|
+
return 'mpx-sticky-section'
|
|
13
|
+
},
|
|
14
|
+
harmony (tag, { el }) {
|
|
15
|
+
el.isBuiltIn = true
|
|
16
|
+
return 'mpx-sticky-section'
|
|
17
|
+
},
|
|
18
|
+
web (tag, { el }) {
|
|
19
|
+
el.isBuiltIn = true
|
|
20
|
+
return 'mpx-sticky-section'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/lib/react/processJSON.js
CHANGED
|
@@ -113,8 +113,9 @@ module.exports = function (jsonContent, {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
if (ctorType === 'page') {
|
|
116
|
-
const keysToExtract = ['navigationStyle']
|
|
116
|
+
const keysToExtract = ['navigationStyle', 'navigationBarTitleText', 'navigationBarTextStyle', 'navigationBarBackgroundColor']
|
|
117
117
|
const configObj = {}
|
|
118
|
+
// 暂时先不注入数据,后续如需要使用再用
|
|
118
119
|
keysToExtract.forEach(key => {
|
|
119
120
|
if (jsonObj[key]) {
|
|
120
121
|
configObj[key] = jsonObj[key]
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { ComponentType, ReactNode, Component, Fragment, Suspense } from 'react'
|
|
2
|
+
import { View, Text, Image, StyleSheet, TouchableOpacity } from 'react-native'
|
|
3
|
+
import FastImage from '@d11/react-native-fast-image'
|
|
4
|
+
|
|
5
|
+
const styles = StyleSheet.create({
|
|
6
|
+
container: {
|
|
7
|
+
flex: 1,
|
|
8
|
+
padding: 20,
|
|
9
|
+
backgroundColor: '#fff'
|
|
10
|
+
},
|
|
11
|
+
loadingImage: {
|
|
12
|
+
width: 100,
|
|
13
|
+
height: 100,
|
|
14
|
+
marginTop: 220,
|
|
15
|
+
alignSelf: 'center'
|
|
16
|
+
},
|
|
17
|
+
buttonText: {
|
|
18
|
+
color: '#fff',
|
|
19
|
+
fontSize: 16,
|
|
20
|
+
fontWeight: '500',
|
|
21
|
+
textAlign: 'center'
|
|
22
|
+
},
|
|
23
|
+
errorImage: {
|
|
24
|
+
marginTop: 80,
|
|
25
|
+
width: 220,
|
|
26
|
+
aspectRatio: 1,
|
|
27
|
+
alignSelf: 'center'
|
|
28
|
+
},
|
|
29
|
+
errorText: {
|
|
30
|
+
fontSize: 16,
|
|
31
|
+
textAlign: 'center',
|
|
32
|
+
color: '#333',
|
|
33
|
+
marginBottom: 20
|
|
34
|
+
},
|
|
35
|
+
retryButton: {
|
|
36
|
+
position: 'absolute',
|
|
37
|
+
bottom: 54,
|
|
38
|
+
left: 20,
|
|
39
|
+
right: 20,
|
|
40
|
+
backgroundColor: '#fff',
|
|
41
|
+
paddingVertical: 15,
|
|
42
|
+
borderRadius: 30,
|
|
43
|
+
marginTop: 40,
|
|
44
|
+
borderWidth: 1,
|
|
45
|
+
borderColor: '#FF5F00'
|
|
46
|
+
},
|
|
47
|
+
retryButtonText: {
|
|
48
|
+
color: '#FF5F00',
|
|
49
|
+
fontSize: 16,
|
|
50
|
+
fontWeight: '500',
|
|
51
|
+
textAlign: 'center'
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
type AsyncType = 'page' | 'component'
|
|
56
|
+
|
|
57
|
+
interface PropsType<T extends AsyncType> {
|
|
58
|
+
type: T
|
|
59
|
+
props: object
|
|
60
|
+
loading: ComponentType<unknown>
|
|
61
|
+
fallback: ComponentType<unknown>
|
|
62
|
+
children: (props: unknown) => ReactNode
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface StateType {
|
|
66
|
+
hasError: boolean,
|
|
67
|
+
key: number
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface ComponentError extends Error {
|
|
71
|
+
request?: string
|
|
72
|
+
type: 'timeout' | 'fail'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const DefaultLoading = () => {
|
|
76
|
+
return (
|
|
77
|
+
<View style={styles.container}>
|
|
78
|
+
<FastImage
|
|
79
|
+
style={styles.loadingImage}
|
|
80
|
+
source={{ uri: 'https://dpubstatic.udache.com/static/dpubimg/439jiCVOtNOnEv9F2LaDs_loading.gif' }}
|
|
81
|
+
resizeMode={FastImage.resizeMode.contain}></FastImage>
|
|
82
|
+
</View>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface DefaultFallbackProps {
|
|
87
|
+
onReload: () => void
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const DefaultFallback = ({ onReload }: DefaultFallbackProps) => {
|
|
91
|
+
return (
|
|
92
|
+
<View style={styles.container}>
|
|
93
|
+
<Image
|
|
94
|
+
source={{ uri: 'https://dpubstatic.udache.com/static/dpubimg/Vak5mZvezPpKV5ZJI6P9b_drn-fallbak.png' }}
|
|
95
|
+
style={styles.errorImage}
|
|
96
|
+
resizeMode="contain"
|
|
97
|
+
/>
|
|
98
|
+
<Text style={styles.errorText}>网络出了点问题,请查看网络环境</Text>
|
|
99
|
+
<TouchableOpacity
|
|
100
|
+
style={styles.retryButton}
|
|
101
|
+
onPress={onReload}
|
|
102
|
+
activeOpacity={0.7}
|
|
103
|
+
>
|
|
104
|
+
<Text style={styles.retryButtonText}>点击重试</Text>
|
|
105
|
+
</TouchableOpacity>
|
|
106
|
+
</View>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default class AsyncContainer extends Component<PropsType<AsyncType>, StateType> {
|
|
111
|
+
private suspenseFallback: ReactNode
|
|
112
|
+
private errorFallback: ReactNode
|
|
113
|
+
|
|
114
|
+
constructor (props: PropsType<AsyncType>) {
|
|
115
|
+
super(props)
|
|
116
|
+
this.state = {
|
|
117
|
+
hasError: false,
|
|
118
|
+
key: 0
|
|
119
|
+
}
|
|
120
|
+
this.suspenseFallback = this.getSuspenseFallback()
|
|
121
|
+
this.errorFallback = this.getErrorFallback()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// render 阶段收集到的错误
|
|
125
|
+
static getDerivedStateFromError (error: ComponentError): StateType | undefined {
|
|
126
|
+
if (error.name === 'ChunkLoadError') {
|
|
127
|
+
return {
|
|
128
|
+
hasError: true,
|
|
129
|
+
key: 0
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
// 被外层捕获
|
|
133
|
+
throw error
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
componentDidCatch (error: ComponentError): void {
|
|
138
|
+
if (error.name === 'ChunkLoadError' && this.props.type === 'component') {
|
|
139
|
+
const request = error.request || ''
|
|
140
|
+
const subpackage = request.split('/').filter((i: string) => !!i)[0]
|
|
141
|
+
global.onLazyLoadError({
|
|
142
|
+
type: 'subpackage',
|
|
143
|
+
subpackage: [subpackage],
|
|
144
|
+
errMsg: `loadSubpackage: ${error.type}`
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
reloadPage () {
|
|
150
|
+
this.setState((prevState) => {
|
|
151
|
+
return {
|
|
152
|
+
hasError: false,
|
|
153
|
+
key: prevState.key + 1
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getSuspenseFallback () {
|
|
159
|
+
if (this.props.type === 'page') {
|
|
160
|
+
const Fallback = this.props.loading || DefaultLoading
|
|
161
|
+
return <Fallback />
|
|
162
|
+
} else {
|
|
163
|
+
const Fallback = this.props.loading
|
|
164
|
+
return <Fallback {...this.props.props}></Fallback>
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
getErrorFallback () {
|
|
169
|
+
if (this.props.type === 'page') {
|
|
170
|
+
const Fallback = this.props.fallback as ComponentType<DefaultFallbackProps> || DefaultFallback
|
|
171
|
+
return <Fallback onReload={this.reloadPage.bind(this)}></Fallback>
|
|
172
|
+
} else {
|
|
173
|
+
const Fallback = this.props.loading
|
|
174
|
+
return <Fallback {...this.props.props}></Fallback>
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
render () {
|
|
179
|
+
if (this.state.hasError) {
|
|
180
|
+
return this.errorFallback
|
|
181
|
+
} else {
|
|
182
|
+
return (
|
|
183
|
+
<Suspense fallback={this.suspenseFallback} key={this.state.key}>
|
|
184
|
+
{this.props.children(this.props.props)}
|
|
185
|
+
</Suspense>
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContext, Dispatch, MutableRefObject, SetStateAction } from 'react'
|
|
2
|
-
import { NativeSyntheticEvent } from 'react-native'
|
|
2
|
+
import { NativeSyntheticEvent, Animated } from 'react-native'
|
|
3
|
+
import { noop } from '@mpxjs/utils'
|
|
3
4
|
|
|
4
5
|
export type LabelContextValue = MutableRefObject<{
|
|
5
6
|
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void
|
|
@@ -42,15 +43,31 @@ export interface PortalContextValue {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export interface ScrollViewContextValue {
|
|
45
|
-
|
|
46
|
+
gestureRef: React.RefObject<any> | null,
|
|
47
|
+
scrollOffset: Animated.Value
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
export interface RouteContextValue {
|
|
49
51
|
pageId: number
|
|
50
52
|
navigation: Record<string, any>
|
|
51
53
|
}
|
|
54
|
+
export interface MovableAreaContextValue {
|
|
55
|
+
width: number
|
|
56
|
+
height: number
|
|
57
|
+
scaleArea: boolean
|
|
58
|
+
onAreaScale?: (scaleInfo: { scale: number }) => void
|
|
59
|
+
registerMovableView?: (id: string, callbacks: {
|
|
60
|
+
onScale: (scaleInfo: { scale: number }) => void
|
|
61
|
+
onScaleEnd?: () => void
|
|
62
|
+
}) => void
|
|
63
|
+
unregisterMovableView?: (id: string) => void
|
|
64
|
+
}
|
|
52
65
|
|
|
53
|
-
export const MovableAreaContext = createContext({ width: 0, height: 0 })
|
|
66
|
+
export const MovableAreaContext = createContext<MovableAreaContextValue>({ width: 0, height: 0, scaleArea: false })
|
|
67
|
+
export interface StickyContextValue {
|
|
68
|
+
registerStickyHeader: Function,
|
|
69
|
+
unregisterStickyHeader: Function
|
|
70
|
+
}
|
|
54
71
|
|
|
55
72
|
export const FormContext = createContext<FormContextValue | null>(null)
|
|
56
73
|
|
|
@@ -72,6 +89,8 @@ export const SwiperContext = createContext({})
|
|
|
72
89
|
|
|
73
90
|
export const KeyboardAvoidContext = createContext<KeyboardAvoidContextValue | null>(null)
|
|
74
91
|
|
|
75
|
-
export const ScrollViewContext = createContext<ScrollViewContextValue>({ gestureRef: null })
|
|
92
|
+
export const ScrollViewContext = createContext<ScrollViewContextValue>({ gestureRef: null, scrollOffset: new Animated.Value(0) })
|
|
76
93
|
|
|
77
94
|
export const PortalContext = createContext<PortalContextValue>(null as any)
|
|
95
|
+
|
|
96
|
+
export const StickyContext = createContext<StickyContextValue>({ registerStickyHeader: noop, unregisterStickyHeader: noop })
|