Skip to content

Commit d623224

Browse files
authored
feat(popup): lockscroll 增加可选值 strict, 用于支持 iOS12 (jdf2e#2629)
* feat(popup): lockscroll 增加可选值 strict, 用于支持 iOS12 * feat(popup): 更新文档 * feat(popup): 更新文档
1 parent f7c0b40 commit d623224

File tree

8 files changed

+21
-16
lines changed

8 files changed

+21
-16
lines changed

src/packages/overlay/doc.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import { Overlay } from '@nutui/nutui-react'
6666
| --- | --- | --- | --- |
6767
| visible | Whether the current component is displayed | `boolean` | `false` |
6868
| duration | Animation duration, in ms | `number` | `300` |
69-
| lockScroll | Whether the background is locked | `boolean` | `true` |
69+
| lockScroll | Whether the background is locked ,strict is used to support iOS12 | `boolean\|strict` | `true` |
7070
| zIndex | Set component page level | `number` | `1000` |
7171
| closeOnOverlayClick | Tap Mask off | `boolean` | `true` |
7272
| onClick | Triggered when the button is clicked | `event: Event` | `-` |

src/packages/overlay/doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import { Overlay } from '@nutui/nutui-react'
6666
| --- | --- | --- | --- |
6767
| visible | 当前组件是否显示 | `boolean` | `false` |
6868
| duration | 动画时长,单位毫秒 | `number` | `300` |
69-
| lockScroll | 背景是否锁定 | `boolean` | `true` |
69+
| lockScroll | 背景是否锁定,strict 用于支持 iOS12 | `boolean\|strict` | `true` |
7070
| zIndex | 设置组件页面层级 | `number` | `1000` |
7171
| closeOnOverlayClick | 是否点击遮罩关闭 | `boolean` | `true` |
7272
| onClick | 点击时触发 | `event: Event` | `-` |

src/packages/overlay/doc.zh-TW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import { Overlay } from '@nutui/nutui-react'
6666
| --- | --- | --- | --- |
6767
| visible | 當前組件是否顯示 | `boolean` | `false` |
6868
| duration | 動畫時長,單位毫秒 | `number` | `300` |
69-
| lockScroll | 背景是否鎖定 | `boolean` | `true` |
69+
| lockScroll | 背景是否鎖定,strict 用於支援 iOS12 | `boolean\|strict` | `true` |
7070
| zIndex | 設置組件頁面層級 | `number` | `1000` |
7171
| closeOnOverlayClick | 是否點擊遮罩關閉 | `boolean` | `true` |
7272
| onClick | 點擊時觸發 | `event: Event` | `-` |

src/packages/overlay/overlay.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, {
2-
useState,
3-
useEffect,
42
FunctionComponent,
53
MouseEvent,
64
MouseEventHandler,
5+
useEffect,
76
useRef,
7+
useState,
88
} from 'react'
99
import { CSSTransition } from 'react-transition-group'
1010
import { EnterHandler, ExitHandler } from 'react-transition-group/Transition'
@@ -17,7 +17,7 @@ export interface OverlayProps extends BasicComponent {
1717
duration: number
1818
closeOnOverlayClick: boolean
1919
visible: boolean
20-
lockScroll: boolean
20+
lockScroll: boolean | 'strict'
2121
onClick: (event: MouseEvent) => void
2222
afterShow: () => void
2323
afterClose: () => void
@@ -66,7 +66,9 @@ export const Overlay: FunctionComponent<
6666
}
6767
}, [visible])
6868

69-
useLockScroll(nodeRef, !!lockScroll && innerVisible)
69+
const shouldLockScroll = !innerVisible ? false : lockScroll
70+
71+
useLockScroll(nodeRef, shouldLockScroll)
7072

7173
const classes = classNames(classPrefix, className)
7274

src/packages/popup/doc.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import { Popup } from '@nutui/nutui-react'
7979
| duration | Mask animation duration, in ms | `number` | `300` |
8080
| overlayClassName | custom mask class | `string` | `-` |
8181
| overlayStyle | custom mask style | `CSSProperties` | `-` |
82-
| lockScroll | Whether the background is locked | `boolean` | `true` |
82+
| lockScroll | Whether the background is locked ,strict is used to support iOS12 | `boolean\|strict` | `true` |
8383
| overlay | Whether to show the mask | `boolean` | `true` |
8484
| closeOnOverlayClick | Whether to click the mask to close | `boolean` | `true` |
8585
| position | popup location | `top` \| `bottom` \| `left` \| `right` \| `center` | `center` |

src/packages/popup/doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import { Popup } from '@nutui/nutui-react'
7979
| duration | 遮罩动画时长,单位毫秒 | `number` | `300` |
8080
| overlayClassName | 自定义遮罩类名 | `string` | `-` |
8181
| overlayStyle | 自定义遮罩样式 | `CSSProperties` | `-` |
82-
| lockScroll | 背景是否锁定 | `boolean` | `true` |
82+
| lockScroll | 背景是否锁定,strict 用于支持 iOS12 | `boolean\|strict` | `true` |
8383
| overlay | 是否显示遮罩 | `boolean` | `true` |
8484
| closeOnOverlayClick | 是否点击遮罩关闭 | `boolean` | `true` |
8585
| position | 弹出位置 | `top` \| `bottom` \| `left` \| `right` \| `center` | `center` |

src/packages/popup/doc.zh-TW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import { Popup } from '@nutui/nutui-react'
7979
| duration | 遮罩動畫時長,單位秒 | `number` | `0.3` |
8080
| overlayClassName | 自定義遮罩類名 | `string` | `-` |
8181
| overlayStyle | 自定義遮罩樣式 | `CSSProperties` | `-` |
82-
| lockScroll | 背景是否鎖定 | `boolean` | `true` |
82+
| lockScroll | 背景是否鎖定,strict 用於支援 iOS12 | `boolean\|strict` | `true` |
8383
| overlay | 是否顯示遮罩 | `boolean` | `true` |
8484
| closeOnOverlayClick | 是否點擊遮罩關閉 | `boolean` | `true` |
8585
| position | 彈出位置(top,bottom,left,right,center) | `string` | `center` |

src/packages/popup/popup.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import React, {
22
FunctionComponent,
3-
useState,
4-
useEffect,
5-
MouseEventHandler,
63
MouseEvent,
4+
MouseEventHandler,
75
ReactElement,
8-
ReactPortal,
96
ReactNode,
7+
ReactPortal,
8+
useEffect,
9+
useState,
1010
} from 'react'
1111
import { createPortal } from 'react-dom'
1212
import { CSSTransition } from 'react-transition-group'
1313
import classNames from 'classnames'
1414
import { Close } from '@nutui/icons-react'
1515
import { EnterHandler, ExitHandler } from 'react-transition-group/Transition'
16-
import { OverlayProps, defaultOverlayProps } from '@/packages/overlay/overlay'
16+
import { defaultOverlayProps, OverlayProps } from '@/packages/overlay/overlay'
1717
import Overlay from '@/packages/overlay'
1818
import { ComponentDefaults } from '@/utils/typings'
1919
import { useLockScroll } from '@/utils/use-lock-scroll'
@@ -104,7 +104,10 @@ export const Popup: FunctionComponent<
104104
const [innerVisible, setInnerVisible] = useState(visible)
105105
const [showChildren, setShowChildren] = useState(true)
106106
const [transitionName, setTransitionName] = useState('')
107-
useLockScroll(nodeRef, innerVisible && lockScroll)
107+
108+
const shouldLockScroll = !innerVisible ? false : lockScroll
109+
useLockScroll(nodeRef, shouldLockScroll)
110+
108111
const classPrefix = 'nut-popup'
109112
const baseStyle = {
110113
zIndex: index,

0 commit comments

Comments
 (0)