-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: extract a safariKeyboardStore and use closing state to hide the …
…alert
- Loading branch information
1 parent
1ca6d5d
commit e06af0a
Showing
2 changed files
with
44 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { isIOS, isSafari, isTouch } from '../browser' | ||
import * as selection from '../device/selection' | ||
import reactMinistore from './react-ministore' | ||
|
||
const VIRTUAL_KEYBOARD_CLOSE_DURATION = 800 | ||
|
||
const safariKeyboardStore = reactMinistore<{ | ||
open: boolean | ||
closing: boolean | ||
}>({ | ||
open: false, | ||
closing: false, | ||
}) | ||
|
||
/** Updates the safariKeyboardStore state based on the selection. */ | ||
const updateKeyboardState = () => { | ||
const keyboardIsVisible = selection.isActive() | ||
if (safariKeyboardStore.getState().open && !keyboardIsVisible) { | ||
safariKeyboardStore.update({ | ||
closing: true, | ||
}) | ||
setTimeout(() => { | ||
safariKeyboardStore.update({ | ||
closing: false, | ||
}) | ||
}, VIRTUAL_KEYBOARD_CLOSE_DURATION) | ||
} | ||
safariKeyboardStore.update({ | ||
open: keyboardIsVisible, | ||
}) | ||
} | ||
|
||
if (isTouch && isSafari() && !isIOS) { | ||
updateKeyboardState() | ||
document.addEventListener('selectionchange', updateKeyboardState) | ||
} | ||
|
||
export default safariKeyboardStore |