Skip to content

Commit

Permalink
Mobile: Fixes #9376: Sidebar is not dismissed when creating a note
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Nov 26, 2023
1 parent 24ed5bd commit fec8c61
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
17 changes: 11 additions & 6 deletions packages/app-mobile/components/ActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const React = require('react');
import { useState, useCallback, useMemo } from 'react';

const Icon = require('react-native-vector-icons/Ionicons').default;
import { FAB, Portal } from 'react-native-paper';
import { _ } from '@joplin/lib/locale';
import { Dispatch } from 'redux';
const Icon = require('react-native-vector-icons/Ionicons').default;

// eslint-disable-next-line no-undef -- Don't know why it says React is undefined when it's defined above
type FABGroupProps = React.ComponentProps<typeof FAB.Group>;

type OnButtonPress = ()=> void;
interface ButtonSpec {
Expand All @@ -19,6 +21,7 @@ interface ActionButtonProps {

// If not given, an "add" button will be used.
mainButton?: ButtonSpec;
dispatch: Dispatch;
}

const defaultOnPress = () => {};
Expand All @@ -36,10 +39,12 @@ const useIcon = (iconName: string) => {

const ActionButton = (props: ActionButtonProps) => {
const [open, setOpen] = useState(false);
const onMenuToggled = useCallback(
(state: { open: boolean }) => setOpen(state.open)
, [setOpen]);

const onMenuToggled: FABGroupProps['onStateChange'] = useCallback(state => {
props.dispatch({
type: 'SIDE_MENU_CLOSE',
});
setOpen(state.open);
}, [setOpen, props.dispatch]);

const actions = useMemo(() => (props.buttons ?? []).map(button => {
return {
Expand Down
4 changes: 1 addition & 3 deletions packages/app-mobile/components/NoteEditor/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ interface ActionButtonProps {
onPress: Callback;
}

const ActionButton = (
props: ActionButtonProps,
) => {
const ActionButton = (props: ActionButtonProps) => {
return (
<CustomButton
themeId={props.themeId}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-mobile/components/screens/Note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ class NoteScreenComponent extends BaseScreenComponent {

if (this.state.mode === 'edit') return null;

return <ActionButton mainButton={editButton} />;
return <ActionButton mainButton={editButton} dispatch={this.props.dispatch} />;
};

// Save button is not really needed anymore with the improved save logic
Expand Down
2 changes: 1 addition & 1 deletion packages/app-mobile/components/screens/Notes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class NotesScreenComponent extends BaseScreenComponent<any> {
color: '#9b59b6',
icon: 'document',
});
return <ActionButton buttons={buttons}/>;
return <ActionButton buttons={buttons} dispatch={this.props.dispatch}/>;
}
return null;
};
Expand Down

0 comments on commit fec8c61

Please sign in to comment.