feat: Added above-keyboard toolbar to Super notes on mobile for formatting & selecting blocks (#2189)

This commit is contained in:
Aman Harwara
2023-02-01 13:59:51 +05:30
committed by GitHub
parent d33c737f86
commit 4a3f9f12e7
48 changed files with 629 additions and 183 deletions

View File

@@ -0,0 +1,53 @@
import { classNames, ReactNativeToWebEvent } from '@standardnotes/snjs'
import { useEffect, useState } from 'react'
import { useApplication } from '../ApplicationProvider'
import Icon from '../Icon/Icon'
const IosKeyboardClose = () => {
const application = useApplication()
const [isVisible, setIsVisible] = useState(false)
const [isFocusInSuperEditor, setIsFocusInSuperEditor] = useState(
() => !!document.activeElement?.closest('#blocks-editor'),
)
useEffect(() => {
return application.addNativeMobileEventListener((event) => {
if (event === ReactNativeToWebEvent.KeyboardWillShow) {
setIsVisible(true)
} else if (event === ReactNativeToWebEvent.KeyboardWillHide) {
setIsVisible(false)
}
})
}, [application])
useEffect(() => {
const handleFocusChange = () => {
setIsFocusInSuperEditor(!!document.activeElement?.closest('#blocks-editor'))
}
document.addEventListener('focusin', handleFocusChange)
document.addEventListener('focusout', handleFocusChange)
return () => {
document.removeEventListener('focusin', handleFocusChange)
document.removeEventListener('focusout', handleFocusChange)
}
}, [])
if (!isVisible) {
return null
}
return (
<button
className={classNames(
'absolute bottom-3 right-3 rounded-full border border-border bg-contrast p-3',
isFocusInSuperEditor && 'hidden',
)}
>
<Icon type="keyboard-close" />
</button>
)
}
export default IosKeyboardClose