chore: add safe area padding to editor content + only send resize event on android if edge-to-edge [skip e2e]
This commit is contained in:
@@ -44,6 +44,8 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
|
|||||||
|
|
||||||
const [showAndroidWebviewUpdatePrompt, setShowAndroidWebviewUpdatePrompt] = useState(false)
|
const [showAndroidWebviewUpdatePrompt, setShowAndroidWebviewUpdatePrompt] = useState(false)
|
||||||
|
|
||||||
|
const insets = useSafeAreaInsets()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const removeStateServiceListener = stateService.addEventObserver((event: ReactNativeToWebEvent) => {
|
const removeStateServiceListener = stateService.addEventObserver((event: ReactNativeToWebEvent) => {
|
||||||
webViewRef.current?.postMessage(JSON.stringify({ reactNativeEvent: event, messageType: 'event' }))
|
webViewRef.current?.postMessage(JSON.stringify({ reactNativeEvent: event, messageType: 'event' }))
|
||||||
@@ -95,7 +97,7 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
|
|||||||
|
|
||||||
const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', (e) => {
|
const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', (e) => {
|
||||||
// iOS handles this using the `willChangeFrame` event instead
|
// iOS handles this using the `willChangeFrame` event instead
|
||||||
if (Platform.OS === 'android') {
|
if (Platform.OS === 'android' && insets.bottom > 0) {
|
||||||
fireKeyboardSizeChangeEvent(e)
|
fireKeyboardSizeChangeEvent(e)
|
||||||
webViewRef.current?.postMessage(
|
webViewRef.current?.postMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -109,7 +111,7 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
|
|||||||
|
|
||||||
const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => {
|
const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => {
|
||||||
// iOS handles this using the `willChangeFrame` event instead
|
// iOS handles this using the `willChangeFrame` event instead
|
||||||
if (Platform.OS === 'android') {
|
if (Platform.OS === 'android' && insets.bottom > 0) {
|
||||||
webViewRef.current?.postMessage(
|
webViewRef.current?.postMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
reactNativeEvent: ReactNativeToWebEvent.KeyboardDidHide,
|
reactNativeEvent: ReactNativeToWebEvent.KeyboardDidHide,
|
||||||
@@ -362,7 +364,6 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
|
|||||||
})
|
})
|
||||||
}, [device])
|
}, [device])
|
||||||
|
|
||||||
const insets = useSafeAreaInsets()
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!didAppLaunch) {
|
if (!didAppLaunch) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { ElementIds } from '@/Constants/ElementIDs'
|
||||||
|
import { classNames, EditorLineWidth } from '@standardnotes/snjs'
|
||||||
|
import { CSSProperties, ForwardedRef, forwardRef, ReactNode } from 'react'
|
||||||
|
import { EditorMargins, EditorMaxWidths } from '../EditorWidthSelectionModal/EditorWidths'
|
||||||
|
import { useAvailableSafeAreaPadding } from '@/Hooks/useSafeAreaPadding'
|
||||||
|
|
||||||
|
export const EditorContentWithSafeAreaPadding = forwardRef(function EditorContentWithSafeAreaPadding(
|
||||||
|
{
|
||||||
|
editorLineWidth,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
editorLineWidth: EditorLineWidth
|
||||||
|
children: NonNullable<ReactNode>
|
||||||
|
},
|
||||||
|
ref: ForwardedRef<HTMLDivElement>,
|
||||||
|
) {
|
||||||
|
const { hasBottomInset } = useAvailableSafeAreaPadding()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
id={ElementIds.EditorContent}
|
||||||
|
className={classNames(
|
||||||
|
ElementIds.EditorContent,
|
||||||
|
'z-editor-content overflow-auto sm:[&>*]:mx-[var(--editor-margin)] sm:[&>*]:max-w-[var(--editor-max-width)]',
|
||||||
|
hasBottomInset && 'pb-safe-bottom',
|
||||||
|
)}
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
'--editor-margin': EditorMargins[editorLineWidth],
|
||||||
|
'--editor-max-width': EditorMaxWidths[editorLineWidth],
|
||||||
|
} as CSSProperties
|
||||||
|
}
|
||||||
|
ref={ref}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -30,7 +30,7 @@ import {
|
|||||||
LocalPrefKey,
|
LocalPrefKey,
|
||||||
} from '@standardnotes/snjs'
|
} from '@standardnotes/snjs'
|
||||||
import { confirmDialog, DELETE_NOTE_KEYBOARD_COMMAND, KeyboardKey } from '@standardnotes/ui-services'
|
import { confirmDialog, DELETE_NOTE_KEYBOARD_COMMAND, KeyboardKey } from '@standardnotes/ui-services'
|
||||||
import { ChangeEventHandler, createRef, CSSProperties, FocusEvent, KeyboardEventHandler, RefObject } from 'react'
|
import { ChangeEventHandler, createRef, FocusEvent, KeyboardEventHandler, RefObject } from 'react'
|
||||||
import { SuperEditor } from '../SuperEditor/SuperEditor'
|
import { SuperEditor } from '../SuperEditor/SuperEditor'
|
||||||
import IndicatorCircle from '../IndicatorCircle/IndicatorCircle'
|
import IndicatorCircle from '../IndicatorCircle/IndicatorCircle'
|
||||||
import LinkedItemBubblesContainer from '../LinkedItems/LinkedItemBubblesContainer'
|
import LinkedItemBubblesContainer from '../LinkedItems/LinkedItemBubblesContainer'
|
||||||
@@ -47,13 +47,13 @@ import {
|
|||||||
import { SuperEditorContentId } from '../SuperEditor/Constants'
|
import { SuperEditorContentId } from '../SuperEditor/Constants'
|
||||||
import { NoteViewController } from './Controller/NoteViewController'
|
import { NoteViewController } from './Controller/NoteViewController'
|
||||||
import { PlainEditor, PlainEditorInterface } from './PlainEditor/PlainEditor'
|
import { PlainEditor, PlainEditorInterface } from './PlainEditor/PlainEditor'
|
||||||
import { EditorMargins, EditorMaxWidths } from '../EditorWidthSelectionModal/EditorWidths'
|
|
||||||
import NoteStatusIndicator, { NoteStatus } from './NoteStatusIndicator'
|
import NoteStatusIndicator, { NoteStatus } from './NoteStatusIndicator'
|
||||||
import CollaborationInfoHUD from './CollaborationInfoHUD'
|
import CollaborationInfoHUD from './CollaborationInfoHUD'
|
||||||
import Button from '../Button/Button'
|
import Button from '../Button/Button'
|
||||||
import ModalOverlay from '../Modal/ModalOverlay'
|
import ModalOverlay from '../Modal/ModalOverlay'
|
||||||
import NoteConflictResolutionModal from './NoteConflictResolutionModal/NoteConflictResolutionModal'
|
import NoteConflictResolutionModal from './NoteConflictResolutionModal/NoteConflictResolutionModal'
|
||||||
import Icon from '../Icon/Icon'
|
import Icon from '../Icon/Icon'
|
||||||
|
import { EditorContentWithSafeAreaPadding } from './EditorContentWithSafeAreaPadding'
|
||||||
|
|
||||||
function sortAlphabetically(array: ComponentInterface[]): ComponentInterface[] {
|
function sortAlphabetically(array: ComponentInterface[]): ComponentInterface[] {
|
||||||
return array.sort((a, b) => (a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1))
|
return array.sort((a, b) => (a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1))
|
||||||
@@ -955,20 +955,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div
|
<EditorContentWithSafeAreaPadding editorLineWidth={this.state.editorLineWidth} ref={this.editorContentRef}>
|
||||||
id={ElementIds.EditorContent}
|
|
||||||
className={classNames(
|
|
||||||
ElementIds.EditorContent,
|
|
||||||
'z-editor-content overflow-auto sm:[&>*]:mx-[var(--editor-margin)] sm:[&>*]:max-w-[var(--editor-max-width)]',
|
|
||||||
)}
|
|
||||||
style={
|
|
||||||
{
|
|
||||||
'--editor-margin': EditorMargins[this.state.editorLineWidth],
|
|
||||||
'--editor-max-width': EditorMaxWidths[this.state.editorLineWidth],
|
|
||||||
} as CSSProperties
|
|
||||||
}
|
|
||||||
ref={this.editorContentRef}
|
|
||||||
>
|
|
||||||
{editorMode === 'component' && this.state.editorComponentViewer && (
|
{editorMode === 'component' && this.state.editorComponentViewer && (
|
||||||
<div className="component-view relative flex-grow">
|
<div className="component-view relative flex-grow">
|
||||||
{this.state.paneGestureEnabled && <div className="absolute left-0 top-0 h-full w-[20px] md:hidden" />}
|
{this.state.paneGestureEnabled && <div className="absolute left-0 top-0 h-full w-[20px] md:hidden" />}
|
||||||
@@ -1009,7 +996,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</EditorContentWithSafeAreaPadding>
|
||||||
|
|
||||||
<div id="editor-pane-component-stack">
|
<div id="editor-pane-component-stack">
|
||||||
{this.state.availableStackComponents.length > 0 && (
|
{this.state.availableStackComponents.length > 0 && (
|
||||||
|
|||||||
Reference in New Issue
Block a user