From 88017ce3d9c84f0383e147179d88c0fcb6538331 Mon Sep 17 00:00:00 2001 From: Mo Date: Sat, 29 Oct 2022 14:53:03 -0500 Subject: [PATCH] fix(mobile): note view hide bar options on editor focus (#1903) --- .../ApplicationView/ApplicationView.tsx | 32 +++---- .../Components/NoteView/NoteView.tsx | 86 +++++++++---------- .../ResponsivePane/ResponsivePaneProvider.tsx | 2 +- .../NativeMobileWeb/useAndroidBackHandler.tsx | 2 +- 4 files changed, 56 insertions(+), 66 deletions(-) diff --git a/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx b/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx index 255bd0b3b..b4b4b7a0d 100644 --- a/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx +++ b/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx @@ -174,28 +174,22 @@ const ApplicationView: FunctionComponent = ({ application, mainApplicatio }, [needsUnlock, launched]) const renderChallenges = useCallback(() => { - return ( - - {challenges.map((challenge) => { - return ( -
- -
- ) - })} -
- ) + return challenges.map((challenge) => ( +
+ +
+ )) }, [viewControllerManager, challenges, mainApplicationGroup, removeChallenge, application]) if (!renderAppContents) { - return renderChallenges() + return {renderChallenges()} } return ( diff --git a/packages/web/src/javascripts/Components/NoteView/NoteView.tsx b/packages/web/src/javascripts/Components/NoteView/NoteView.tsx index 16ddcf0d2..e59559182 100644 --- a/packages/web/src/javascripts/Components/NoteView/NoteView.tsx +++ b/packages/web/src/javascripts/Components/NoteView/NoteView.tsx @@ -17,7 +17,7 @@ import { EditorFontSize, NoteType, } from '@standardnotes/snjs' -import { debounce, isDesktopApplication } from '@/Utils' +import { debounce, isDesktopApplication, isMobileScreen } from '@/Utils' import { EditorEventSource } from '../../Types/EditorEventSource' import { confirmDialog, KeyboardModifier, KeyboardKey } from '@standardnotes/ui-services' import { STRING_DELETE_PLACEHOLDER_ATTEMPT, STRING_DELETE_LOCKED_ATTEMPT, StringDeleteNote } from '@/Constants/Strings' @@ -74,6 +74,7 @@ type State = { /** Setting to true then false will allow the main content textarea to be destroyed * then re-initialized. Used when reloading spellcheck status. */ textareaUnloading: boolean + plaintextEditorFocused?: boolean leftResizerWidth: number leftResizerOffset: number @@ -104,7 +105,6 @@ class NoteView extends PureComponent { private lastEditorFocusEventSource?: EditorEventSource onEditorComponentLoad?: () => void - private scrollPosition = 0 private removeTrashKeyObserver?: () => void private removeTabObserver?: () => void private removeComponentStreamObserver?: () => void @@ -193,8 +193,6 @@ class NoteView extends PureComponent { ;(this.onPanelResizeFinish as unknown) = undefined ;(this.stackComponentExpanded as unknown) = undefined ;(this.toggleStackComponent as unknown) = undefined - ;(this.setScrollPosition as unknown) = undefined - ;(this.resetScrollPosition as unknown) = undefined ;(this.onSystemEditorLoad as unknown) = undefined ;(this.debounceReloadEditorComponent as unknown) = undefined ;(this.textAreaChangeDebounceSave as unknown) = undefined @@ -644,6 +642,15 @@ class NoteView extends PureComponent { this.application.notifyWebEvent(WebAppEvent.EditorFocused, { eventSource: this.lastEditorFocusEventSource }) } this.lastEditorFocusEventSource = undefined + this.setState({ plaintextEditorFocused: true }) + } + + onContentBlur = () => { + if (this.lastEditorFocusEventSource) { + this.application.notifyWebEvent(WebAppEvent.EditorFocused, { eventSource: this.lastEditorFocusEventSource }) + } + this.lastEditorFocusEventSource = undefined + this.setState({ plaintextEditorFocused: false }) } setShowProtectedOverlay(show: boolean) { @@ -837,16 +844,6 @@ class NoteView extends PureComponent { }) } - setScrollPosition = () => { - const editor = document.getElementById(ElementIds.NoteTextEditor) as HTMLInputElement - this.scrollPosition = editor.scrollTop - } - - resetScrollPosition = () => { - const editor = document.getElementById(ElementIds.NoteTextEditor) as HTMLInputElement - editor.scrollTop = this.scrollPosition - } - onSystemEditorLoad = (ref: HTMLTextAreaElement | null) => { if (this.removeTabObserver || !ref) { return @@ -900,18 +897,12 @@ class NoteView extends PureComponent { }, }) - editor.addEventListener('scroll', this.setScrollPosition) - editor.addEventListener('input', this.resetScrollPosition) - const observer = new MutationObserver((records) => { for (const record of records) { record.removedNodes.forEach((node) => { if (node === editor) { this.removeTabObserver?.() this.removeTabObserver = undefined - editor.removeEventListener('scroll', this.setScrollPosition) - editor.removeEventListener('scroll', this.resetScrollPosition) - this.scrollPosition = 0 } }) } @@ -942,6 +933,8 @@ class NoteView extends PureComponent { ) } + const renderHeaderOptions = isMobileScreen() ? !this.state.plaintextEditorFocused : true + return (
{ updateSavingIndicator={this.state.updateSavingIndicator} />
-
- - - - -
+ {renderHeaderOptions && ( +
+ + + + +
+ )} @@ -1073,6 +1068,7 @@ class NoteView extends PureComponent { id={ElementIds.NoteTextEditor} onChange={this.onTextAreaChange} onFocus={this.onContentFocus} + onBlur={this.onContentBlur} readOnly={this.state.noteLocked} ref={(ref) => ref && this.onSystemEditorLoad(ref)} spellCheck={this.state.spellcheck} diff --git a/packages/web/src/javascripts/Components/ResponsivePane/ResponsivePaneProvider.tsx b/packages/web/src/javascripts/Components/ResponsivePane/ResponsivePaneProvider.tsx index 6e0de054a..943e881e6 100644 --- a/packages/web/src/javascripts/Components/ResponsivePane/ResponsivePaneProvider.tsx +++ b/packages/web/src/javascripts/Components/ResponsivePane/ResponsivePaneProvider.tsx @@ -54,7 +54,7 @@ function useStateRef(state: State): MutableRefObject { return ref } -const MemoizedChildren = memo(({ children }: ChildrenProps) =>
{children}
) +const MemoizedChildren = memo(({ children }: ChildrenProps) => <>{children}) const ResponsivePaneProvider = ({ paneController, children }: ProviderProps) => { const currentSelectedPane = paneController.currentPane diff --git a/packages/web/src/javascripts/NativeMobileWeb/useAndroidBackHandler.tsx b/packages/web/src/javascripts/NativeMobileWeb/useAndroidBackHandler.tsx index e1521d5cd..3ec27d422 100644 --- a/packages/web/src/javascripts/NativeMobileWeb/useAndroidBackHandler.tsx +++ b/packages/web/src/javascripts/NativeMobileWeb/useAndroidBackHandler.tsx @@ -25,7 +25,7 @@ type ProviderProps = { application: WebApplication } & ChildrenProps -const MemoizedChildren = memo(({ children }: ChildrenProps) =>
{children}
) +const MemoizedChildren = memo(({ children }: ChildrenProps) => <>{children}) const AndroidBackHandlerProvider = ({ application, children }: ProviderProps) => { const addAndroidBackHandler = useCallback(