fix(mobile): note view hide bar options on editor focus (#1903)

This commit is contained in:
Mo
2022-10-29 14:53:03 -05:00
committed by GitHub
parent b9b4bdf257
commit 88017ce3d9
4 changed files with 56 additions and 66 deletions

View File

@@ -174,28 +174,22 @@ const ApplicationView: FunctionComponent<Props> = ({ application, mainApplicatio
}, [needsUnlock, launched]) }, [needsUnlock, launched])
const renderChallenges = useCallback(() => { const renderChallenges = useCallback(() => {
return ( return challenges.map((challenge) => (
<AndroidBackHandlerProvider application={application}> <div className="sk-modal" key={`${challenge.id}${application.ephemeralIdentifier}`}>
{challenges.map((challenge) => { <ChallengeModal
return ( key={`${challenge.id}${application.ephemeralIdentifier}`}
<div className="sk-modal" key={`${challenge.id}${application.ephemeralIdentifier}`}> application={application}
<ChallengeModal viewControllerManager={viewControllerManager}
key={`${challenge.id}${application.ephemeralIdentifier}`} mainApplicationGroup={mainApplicationGroup}
application={application} challenge={challenge}
viewControllerManager={viewControllerManager} onDismiss={removeChallenge}
mainApplicationGroup={mainApplicationGroup} />
challenge={challenge} </div>
onDismiss={removeChallenge} ))
/>
</div>
)
})}
</AndroidBackHandlerProvider>
)
}, [viewControllerManager, challenges, mainApplicationGroup, removeChallenge, application]) }, [viewControllerManager, challenges, mainApplicationGroup, removeChallenge, application])
if (!renderAppContents) { if (!renderAppContents) {
return renderChallenges() return <AndroidBackHandlerProvider application={application}>{renderChallenges()}</AndroidBackHandlerProvider>
} }
return ( return (

View File

@@ -17,7 +17,7 @@ import {
EditorFontSize, EditorFontSize,
NoteType, NoteType,
} from '@standardnotes/snjs' } from '@standardnotes/snjs'
import { debounce, isDesktopApplication } from '@/Utils' import { debounce, isDesktopApplication, isMobileScreen } from '@/Utils'
import { EditorEventSource } from '../../Types/EditorEventSource' import { EditorEventSource } from '../../Types/EditorEventSource'
import { confirmDialog, KeyboardModifier, KeyboardKey } from '@standardnotes/ui-services' import { confirmDialog, KeyboardModifier, KeyboardKey } from '@standardnotes/ui-services'
import { STRING_DELETE_PLACEHOLDER_ATTEMPT, STRING_DELETE_LOCKED_ATTEMPT, StringDeleteNote } from '@/Constants/Strings' 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 /** Setting to true then false will allow the main content textarea to be destroyed
* then re-initialized. Used when reloading spellcheck status. */ * then re-initialized. Used when reloading spellcheck status. */
textareaUnloading: boolean textareaUnloading: boolean
plaintextEditorFocused?: boolean
leftResizerWidth: number leftResizerWidth: number
leftResizerOffset: number leftResizerOffset: number
@@ -104,7 +105,6 @@ class NoteView extends PureComponent<NoteViewProps, State> {
private lastEditorFocusEventSource?: EditorEventSource private lastEditorFocusEventSource?: EditorEventSource
onEditorComponentLoad?: () => void onEditorComponentLoad?: () => void
private scrollPosition = 0
private removeTrashKeyObserver?: () => void private removeTrashKeyObserver?: () => void
private removeTabObserver?: () => void private removeTabObserver?: () => void
private removeComponentStreamObserver?: () => void private removeComponentStreamObserver?: () => void
@@ -193,8 +193,6 @@ class NoteView extends PureComponent<NoteViewProps, State> {
;(this.onPanelResizeFinish as unknown) = undefined ;(this.onPanelResizeFinish as unknown) = undefined
;(this.stackComponentExpanded as unknown) = undefined ;(this.stackComponentExpanded as unknown) = undefined
;(this.toggleStackComponent as unknown) = undefined ;(this.toggleStackComponent as unknown) = undefined
;(this.setScrollPosition as unknown) = undefined
;(this.resetScrollPosition as unknown) = undefined
;(this.onSystemEditorLoad as unknown) = undefined ;(this.onSystemEditorLoad as unknown) = undefined
;(this.debounceReloadEditorComponent as unknown) = undefined ;(this.debounceReloadEditorComponent as unknown) = undefined
;(this.textAreaChangeDebounceSave as unknown) = undefined ;(this.textAreaChangeDebounceSave as unknown) = undefined
@@ -644,6 +642,15 @@ class NoteView extends PureComponent<NoteViewProps, State> {
this.application.notifyWebEvent(WebAppEvent.EditorFocused, { eventSource: this.lastEditorFocusEventSource }) this.application.notifyWebEvent(WebAppEvent.EditorFocused, { eventSource: this.lastEditorFocusEventSource })
} }
this.lastEditorFocusEventSource = undefined 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) { setShowProtectedOverlay(show: boolean) {
@@ -837,16 +844,6 @@ class NoteView extends PureComponent<NoteViewProps, State> {
}) })
} }
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) => { onSystemEditorLoad = (ref: HTMLTextAreaElement | null) => {
if (this.removeTabObserver || !ref) { if (this.removeTabObserver || !ref) {
return return
@@ -900,18 +897,12 @@ class NoteView extends PureComponent<NoteViewProps, State> {
}, },
}) })
editor.addEventListener('scroll', this.setScrollPosition)
editor.addEventListener('input', this.resetScrollPosition)
const observer = new MutationObserver((records) => { const observer = new MutationObserver((records) => {
for (const record of records) { for (const record of records) {
record.removedNodes.forEach((node) => { record.removedNodes.forEach((node) => {
if (node === editor) { if (node === editor) {
this.removeTabObserver?.() this.removeTabObserver?.()
this.removeTabObserver = undefined this.removeTabObserver = undefined
editor.removeEventListener('scroll', this.setScrollPosition)
editor.removeEventListener('scroll', this.resetScrollPosition)
this.scrollPosition = 0
} }
}) })
} }
@@ -942,6 +933,8 @@ class NoteView extends PureComponent<NoteViewProps, State> {
) )
} }
const renderHeaderOptions = isMobileScreen() ? !this.state.plaintextEditorFocused : true
return ( return (
<div <div
aria-label="Note" aria-label="Note"
@@ -1005,31 +998,33 @@ class NoteView extends PureComponent<NoteViewProps, State> {
updateSavingIndicator={this.state.updateSavingIndicator} updateSavingIndicator={this.state.updateSavingIndicator}
/> />
</div> </div>
<div className="flex items-center gap-3"> {renderHeaderOptions && (
<LinkedItemsButton <div className="flex items-center gap-3">
filesController={this.viewControllerManager.filesController} <LinkedItemsButton
linkingController={this.viewControllerManager.linkingController} filesController={this.viewControllerManager.filesController}
onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction} linkingController={this.viewControllerManager.linkingController}
featuresController={this.viewControllerManager.featuresController} onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction}
/> featuresController={this.viewControllerManager.featuresController}
<ChangeEditorButton />
application={this.application} <ChangeEditorButton
viewControllerManager={this.viewControllerManager} application={this.application}
onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction} viewControllerManager={this.viewControllerManager}
/> onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction}
<PinNoteButton />
notesController={this.viewControllerManager.notesController} <PinNoteButton
onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction} notesController={this.viewControllerManager.notesController}
/> onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction}
<NotesOptionsPanel />
application={this.application} <NotesOptionsPanel
navigationController={this.viewControllerManager.navigationController} application={this.application}
notesController={this.viewControllerManager.notesController} navigationController={this.viewControllerManager.navigationController}
linkingController={this.viewControllerManager.linkingController} notesController={this.viewControllerManager.notesController}
historyModalController={this.viewControllerManager.historyModalController} linkingController={this.viewControllerManager.linkingController}
onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction} historyModalController={this.viewControllerManager.historyModalController}
/> onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction}
</div> />
</div>
)}
</div> </div>
<LinkedItemBubblesContainer linkingController={this.viewControllerManager.linkingController} /> <LinkedItemBubblesContainer linkingController={this.viewControllerManager.linkingController} />
</div> </div>
@@ -1073,6 +1068,7 @@ class NoteView extends PureComponent<NoteViewProps, State> {
id={ElementIds.NoteTextEditor} id={ElementIds.NoteTextEditor}
onChange={this.onTextAreaChange} onChange={this.onTextAreaChange}
onFocus={this.onContentFocus} onFocus={this.onContentFocus}
onBlur={this.onContentBlur}
readOnly={this.state.noteLocked} readOnly={this.state.noteLocked}
ref={(ref) => ref && this.onSystemEditorLoad(ref)} ref={(ref) => ref && this.onSystemEditorLoad(ref)}
spellCheck={this.state.spellcheck} spellCheck={this.state.spellcheck}

View File

@@ -54,7 +54,7 @@ function useStateRef<State>(state: State): MutableRefObject<State> {
return ref return ref
} }
const MemoizedChildren = memo(({ children }: ChildrenProps) => <div>{children}</div>) const MemoizedChildren = memo(({ children }: ChildrenProps) => <>{children}</>)
const ResponsivePaneProvider = ({ paneController, children }: ProviderProps) => { const ResponsivePaneProvider = ({ paneController, children }: ProviderProps) => {
const currentSelectedPane = paneController.currentPane const currentSelectedPane = paneController.currentPane

View File

@@ -25,7 +25,7 @@ type ProviderProps = {
application: WebApplication application: WebApplication
} & ChildrenProps } & ChildrenProps
const MemoizedChildren = memo(({ children }: ChildrenProps) => <div>{children}</div>) const MemoizedChildren = memo(({ children }: ChildrenProps) => <>{children}</>)
const AndroidBackHandlerProvider = ({ application, children }: ProviderProps) => { const AndroidBackHandlerProvider = ({ application, children }: ProviderProps) => {
const addAndroidBackHandler = useCallback( const addAndroidBackHandler = useCallback(