@gm-mobile/mp 3.9.3-beta.27 → 3.9.3-beta.30
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/package.json +5 -5
- package/src/component/page/base.less +11 -0
- package/src/component/page/page.tsx +58 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-mobile/mp",
|
|
3
|
-
"version": "3.9.3-beta.
|
|
3
|
+
"version": "3.9.3-beta.30",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-mobile#readme",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"url": "https://github.com/gmfe/gm-mobile/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@gm-mobile/c-react": "^3.9.3-beta.
|
|
25
|
-
"@gm-mobile/c-tool": "^3.9.3-beta.
|
|
26
|
-
"@gm-mobile/locales": "^3.9.3-beta.
|
|
24
|
+
"@gm-mobile/c-react": "^3.9.3-beta.30",
|
|
25
|
+
"@gm-mobile/c-tool": "^3.9.3-beta.30",
|
|
26
|
+
"@gm-mobile/locales": "^3.9.3-beta.30"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@tarojs/components": "3.0.18",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"prop-types": "^15.7.2",
|
|
34
34
|
"react": "^16.13.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "31da7b0c46139802e33a24a4cd6d016de3996fe6"
|
|
37
37
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useEffect,
|
|
3
|
+
useRef,
|
|
4
|
+
FC,
|
|
5
|
+
useState,
|
|
6
|
+
ReactNode,
|
|
7
|
+
CSSProperties,
|
|
8
|
+
} from 'react'
|
|
2
9
|
import { Flex, LayoutRoot, LayoutRootV1, Loading } from '@gm-mobile/c-react'
|
|
3
|
-
import { ScrollView } from '@tarojs/components'
|
|
10
|
+
import { ScrollView, View } from '@tarojs/components'
|
|
4
11
|
import PageBase, { PageProps } from './base'
|
|
5
12
|
import { pxTransform } from '@tarojs/taro'
|
|
6
13
|
|
|
7
14
|
interface PageMPProps extends PageProps {
|
|
15
|
+
/** 最大宽度,默认480(ipad),对ipad设备做居中变窄处理,设置1025(iPad pro 12.9 inch)可以跳过处理 */
|
|
16
|
+
maxWidth?: number
|
|
8
17
|
onRefresh?: () => Promise<any>
|
|
9
18
|
/** 上滑加载更多事件。如果promise返回一个空数组,表示没有更多了 */
|
|
10
19
|
onLoadMore?: () => Promise<Array<any> | undefined>
|
|
@@ -12,10 +21,16 @@ interface PageMPProps extends PageProps {
|
|
|
12
21
|
|
|
13
22
|
const PageMP: FC<PageMPProps> = ({
|
|
14
23
|
children,
|
|
24
|
+
maxWidth = 480,
|
|
15
25
|
onRefresh,
|
|
16
26
|
onLoadMore,
|
|
27
|
+
style,
|
|
17
28
|
...props
|
|
18
29
|
}) => {
|
|
30
|
+
const { screenWidth } = wx.getSystemInfoSync()
|
|
31
|
+
const transformRatio = maxWidth / screenWidth
|
|
32
|
+
const transform = screenWidth > maxWidth
|
|
33
|
+
|
|
19
34
|
const [state, setState] = useState({
|
|
20
35
|
refreshing: false,
|
|
21
36
|
loadingMore: false,
|
|
@@ -56,6 +71,7 @@ const PageMP: FC<PageMPProps> = ({
|
|
|
56
71
|
}
|
|
57
72
|
|
|
58
73
|
const loadMore = async () => {
|
|
74
|
+
console.log('load more')
|
|
59
75
|
setState((state) => {
|
|
60
76
|
return {
|
|
61
77
|
...state,
|
|
@@ -74,24 +90,39 @@ const PageMP: FC<PageMPProps> = ({
|
|
|
74
90
|
}
|
|
75
91
|
})
|
|
76
92
|
}
|
|
93
|
+
const withScrollView = !!onRefresh || !!onLoadMore
|
|
94
|
+
|
|
95
|
+
const layoutStyle: CSSProperties = transform
|
|
96
|
+
? {
|
|
97
|
+
position: 'absolute',
|
|
98
|
+
width: '100%',
|
|
99
|
+
height: `calc(100vh / ${transformRatio})`,
|
|
100
|
+
}
|
|
101
|
+
: {}
|
|
77
102
|
|
|
78
|
-
|
|
103
|
+
const page = (
|
|
79
104
|
<>
|
|
80
|
-
<PageBase
|
|
81
|
-
{
|
|
105
|
+
<PageBase
|
|
106
|
+
{...props}
|
|
107
|
+
style={{
|
|
108
|
+
...style,
|
|
109
|
+
height: transform ? `calc(100vh / ${transformRatio})` : undefined,
|
|
110
|
+
}}
|
|
111
|
+
>
|
|
112
|
+
{withScrollView && (
|
|
82
113
|
<ScrollView
|
|
83
114
|
className='m-flex'
|
|
84
115
|
style={{ height: '100%' }}
|
|
85
116
|
enableBackToTop
|
|
86
117
|
scrollY
|
|
87
|
-
refresherEnabled
|
|
118
|
+
refresherEnabled={!!onRefresh}
|
|
88
119
|
scrollWithAnimation
|
|
89
120
|
scrollAnchoring
|
|
90
121
|
refresherBackground='transparent'
|
|
91
122
|
refresherTriggered={state.refreshing}
|
|
92
123
|
lowerThreshold={50}
|
|
93
|
-
onRefresherRefresh={() => refresh()}
|
|
94
|
-
onScrollToLower={() => loadMore()}
|
|
124
|
+
onRefresherRefresh={onRefresh ? () => refresh() : undefined}
|
|
125
|
+
onScrollToLower={onLoadMore ? () => loadMore() : undefined}
|
|
95
126
|
>
|
|
96
127
|
{children}
|
|
97
128
|
{state.loadingMore && (
|
|
@@ -101,12 +132,28 @@ const PageMP: FC<PageMPProps> = ({
|
|
|
101
132
|
)}
|
|
102
133
|
</ScrollView>
|
|
103
134
|
)}
|
|
104
|
-
{!
|
|
135
|
+
{!withScrollView && children}
|
|
105
136
|
</PageBase>
|
|
106
|
-
<LayoutRoot />
|
|
107
|
-
<LayoutRootV1 />
|
|
137
|
+
<LayoutRoot style={layoutStyle} />
|
|
138
|
+
<LayoutRootV1 style={layoutStyle} />
|
|
108
139
|
</>
|
|
109
140
|
)
|
|
141
|
+
|
|
142
|
+
if (transform) {
|
|
143
|
+
return (
|
|
144
|
+
<View className='transformer'>
|
|
145
|
+
<View
|
|
146
|
+
className='transformed-page'
|
|
147
|
+
style={{
|
|
148
|
+
transform: `scale(${transformRatio})`,
|
|
149
|
+
}}
|
|
150
|
+
>
|
|
151
|
+
{page}
|
|
152
|
+
</View>
|
|
153
|
+
</View>
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
return page
|
|
110
157
|
}
|
|
111
158
|
|
|
112
159
|
export default PageMP
|