@gm-mobile/mp 3.9.2 → 3.9.3-beta.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-mobile/mp",
3
- "version": "3.9.2",
3
+ "version": "3.9.3-beta.11",
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.2",
25
- "@gm-mobile/c-tool": "^3.9.2",
26
- "@gm-mobile/locales": "^3.9.2"
24
+ "@gm-mobile/c-react": "^3.9.3-beta.11",
25
+ "@gm-mobile/c-tool": "^3.9.3-beta.11",
26
+ "@gm-mobile/locales": "^3.9.3-beta.11"
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": "cce754c81f0dffe220595dc437559cc26c08e57f"
36
+ "gitHead": "99380ef9295d7feceb202907caa045dbbf610699"
37
37
  }
@@ -0,0 +1,10 @@
1
+ @supports (bottom: constant(safe-area-inset-bottom)) or
2
+ (bottom: env(safe-area-inset-bottom)) {
3
+ .m-page {
4
+ padding-bottom: 0;
5
+ }
6
+ .m-page.safe-bottom {
7
+ padding-bottom: constant(safe-area-inset-bottom); /* 兼容 iOS < 11.2 */
8
+ padding-bottom: env(safe-area-inset-bottom); /* 兼容 iOS >= 11.2 */
9
+ }
10
+ }
@@ -0,0 +1,98 @@
1
+ import React, { CSSProperties, FC, HtmlHTMLAttributes, ReactNode } from 'react'
2
+ import classNames from 'classnames'
3
+ import { Flex, Status, View } from '@gm-mobile/c-react/src'
4
+ import './base.less'
5
+ import SafeBottomMP from '../safe_bottom/safe_bottom'
6
+
7
+ interface PageProps extends HtmlHTMLAttributes<HTMLDivElement> {
8
+ loading?: boolean
9
+ error?: boolean
10
+ onReload?: () => void
11
+ white?: boolean
12
+ header?: ReactNode
13
+ tabbar?: ReactNode
14
+ top?: ReactNode
15
+ /** bottom位置自带底部安全边距,不需要和safeBottom同时使用 */
16
+ bottom?: ReactNode
17
+ pageClassName?: string
18
+ pageStyle?: CSSProperties
19
+ /** 底部安全区域 */
20
+ safeBottom?: boolean
21
+ /** 用于放置绝对定位组件 */
22
+ extra?: ReactNode
23
+ }
24
+
25
+ const Page: FC<PageProps> = ({
26
+ loading,
27
+ error,
28
+ onReload,
29
+ white,
30
+ header,
31
+ tabbar,
32
+ top,
33
+ bottom,
34
+ children,
35
+ className,
36
+ pageClassName,
37
+ pageStyle,
38
+ safeBottom,
39
+ extra,
40
+ ...rest
41
+ }) => {
42
+ return (
43
+ <Flex
44
+ {...rest}
45
+ column
46
+ className={classNames(
47
+ 'm-page',
48
+ {
49
+ 'm-page-white': white,
50
+ 'safe-bottom': safeBottom,
51
+ },
52
+ className
53
+ )}
54
+ >
55
+ {loading && (
56
+ <Status
57
+ className='m-status'
58
+ type='loading'
59
+ style={{ marginTop: '40vh' }}
60
+ />
61
+ )}
62
+ {error && (
63
+ <Status
64
+ className='m-status'
65
+ type='error'
66
+ style={{ marginTop: '40vh' }}
67
+ onReload={onReload}
68
+ />
69
+ )}
70
+ {!loading && !error && (
71
+ <>
72
+ {header && (
73
+ <Flex column none className='m-page-header m-flex-none'>
74
+ {header}
75
+ </Flex>
76
+ )}
77
+ {top && <View className='m-top m-flex-none'>{top}</View>}
78
+ <View
79
+ className={classNames('m-page-content', pageClassName)}
80
+ style={pageStyle}
81
+ >
82
+ {children}
83
+ </View>
84
+ {bottom && (
85
+ <SafeBottomMP className='m-bottom m-flex-none'>
86
+ {bottom}
87
+ </SafeBottomMP>
88
+ )}
89
+ </>
90
+ )}
91
+ {extra}
92
+ {tabbar && <View className='m-page-tabbar m-flex-none'>{tabbar}</View>}
93
+ </Flex>
94
+ )
95
+ }
96
+
97
+ export default Page
98
+ export type { PageProps }
@@ -1,12 +1,16 @@
1
- import React, { useEffect, useRef, FC } from 'react'
2
- import {
3
- Page as PageBase,
4
- LayoutRoot,
5
- LayoutRootV1,
6
- PageProps as PageMPProps,
7
- } from '@gm-mobile/c-react'
1
+ import React, { useEffect, useRef, FC, useState, ReactNode } from 'react'
2
+ import { LayoutRoot, LayoutRootV1 } from '@gm-mobile/c-react'
3
+ import { ScrollView } from '@tarojs/components'
4
+ import PageBase, { PageProps as PageMPProps } from './base'
8
5
 
9
- const PageMP: FC<PageMPProps> = (props) => {
6
+ const PageMP: FC<
7
+ PageMPProps & {
8
+ onRefresh?: () => Promise<any>
9
+ }
10
+ > = ({ children, onRefresh, ...props }) => {
11
+ const [state, setState] = useState({
12
+ refreshing: false,
13
+ })
10
14
  const refLoading = useRef<boolean | undefined>(false)
11
15
  useEffect(() => {
12
16
  // 和之前的不一样
@@ -20,10 +24,46 @@ const PageMP: FC<PageMPProps> = (props) => {
20
24
  refLoading.current = props.loading
21
25
  }
22
26
  }, [props.loading])
27
+ const methods = {
28
+ async refresh() {
29
+ setState((state) => {
30
+ return {
31
+ ...state,
32
+ refreshing: true,
33
+ }
34
+ })
35
+ try {
36
+ onRefresh && (await onRefresh())
37
+ } catch (err) {
38
+ console.error(err)
39
+ }
40
+ setState((state) => {
41
+ return {
42
+ ...state,
43
+ refreshing: false,
44
+ }
45
+ })
46
+ },
47
+ }
23
48
 
24
49
  return (
25
50
  <>
26
- <PageBase {...props} />
51
+ <PageBase {...props}>
52
+ {onRefresh && (
53
+ <ScrollView
54
+ className='m-flex'
55
+ style={{ height: '100%' }}
56
+ scrollY
57
+ refresherEnabled
58
+ refresherBackground='transparent'
59
+ refresherTriggered={state.refreshing}
60
+ onRefresherRefresh={methods.refresh}
61
+ >
62
+ {children}
63
+ </ScrollView>
64
+ )}
65
+ {!onRefresh && children}
66
+ </PageBase>
27
67
  <LayoutRoot />
28
68
  <LayoutRootV1 />
29
69
  </>
@@ -0,0 +1 @@
1
+ export { default as SafeBottom } from './safe_bottom'
@@ -0,0 +1,27 @@
1
+ import React, { memo, FC } from 'react'
2
+ import { View } from '@tarojs/components'
3
+ import classNames from 'classnames'
4
+ import { ViewProps } from '@tarojs/components/types/View'
5
+
6
+ type SafeBottomMPProps = ViewProps
7
+
8
+ const SafeBottomMP: FC<SafeBottomMPProps> = memo(
9
+ ({ className, children, ...rest }) => {
10
+ const { safeArea, screenHeight } = wx.getSystemInfoSync()
11
+ const paddingBottom = screenHeight - safeArea.bottom
12
+
13
+ return (
14
+ <View className={classNames(className)} {...rest}>
15
+ {React.cloneElement((children as React.ReactElement) || <View />, {
16
+ style: {
17
+ paddingBottom:
18
+ paddingBottom > 0 ? `${paddingBottom}px!important` : undefined,
19
+ },
20
+ })}
21
+ </View>
22
+ )
23
+ }
24
+ )
25
+
26
+ export default SafeBottomMP
27
+ export type { SafeBottomMPProps }
package/src/index.ts CHANGED
@@ -12,5 +12,6 @@ export * from './component/counter'
12
12
  export * from './component/status_bar'
13
13
  export * from './component/swiper'
14
14
  export * from './component/safe_header'
15
+ export * from './component/safe_bottom'
15
16
 
16
17
  export { LocalStorage, useFirstDidShow, Router, upload }