1- export const fixedIOS = ( ) => {
2- if ( typeof window === 'undefined' || window . __ios_scroll_fixed__ ) {
3- return
1+ const fixedIOS = ( ) => {
2+ const noop = {
3+ open : ( ) => { } ,
4+ close : ( ) => { }
5+ }
6+ if ( typeof window === 'undefined' ) {
7+ return noop
48 }
5-
6- window . __ios_scroll_fixed__ = true
79
810 const testDiv = document . createElement ( 'div' )
911 document . documentElement . appendChild ( testDiv )
@@ -13,7 +15,7 @@ export const fixedIOS = () => {
1315 window . getComputedStyle ( testDiv ) [ '-webkit-overflow-scrolling' ] === 'touch'
1416 document . documentElement . removeChild ( testDiv )
1517 if ( ! scrollSupport ) {
16- return
18+ return noop
1719 }
1820
1921 let startY = 0
@@ -98,14 +100,33 @@ export const fixedIOS = () => {
98100 startY = evt . touches ? evt . touches [ 0 ] . screenY : evt . screenY
99101 }
100102
101- window . addEventListener (
102- 'touchstart' ,
103- handleTouchstart ,
104- supportsPassiveOption ? { passive : false } : false
105- )
106- window . addEventListener (
107- 'touchmove' ,
108- handleTouchmove ,
109- supportsPassiveOption ? { passive : false } : false
110- )
103+ const open = ( ) => {
104+ if ( window . __ios_scroll_fixed__ ) {
105+ return
106+ }
107+ window . addEventListener (
108+ 'touchstart' ,
109+ handleTouchstart ,
110+ supportsPassiveOption ? { passive : false } : false
111+ )
112+ window . addEventListener (
113+ 'touchmove' ,
114+ handleTouchmove ,
115+ supportsPassiveOption ? { passive : false } : false
116+ )
117+ window . __ios_scroll_fixed__ = true
118+ }
119+
120+ const close = ( ) => {
121+ window . removeEventListener ( 'touchstart' , handleTouchstart , false )
122+ window . removeEventListener ( 'touchmove' , handleTouchmove , false )
123+ window . __ios_scroll_fixed__ = false
124+ }
125+
126+ return {
127+ open,
128+ close
129+ }
111130}
131+
132+ export default fixedIOS ( )
0 commit comments