Skip to content

Commit

Permalink
fix: use React Native Paper menu instead of NativeBase menu
Browse files Browse the repository at this point in the history
fixes crash opening menu on iOS
  • Loading branch information
paulschreiber committed Jun 18, 2024
1 parent 4346a76 commit bebbfe6
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions dev-client/src/screens/ProjectSitesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

import {useCallback, useMemo} from 'react';
import {useCallback, useMemo, useState} from 'react';
import {useTranslation} from 'react-i18next';
import {Menu} from 'react-native-paper';

import {MaterialTopTabScreenProps} from '@react-navigation/material-top-tabs';
import type {CompositeScreenProps} from '@react-navigation/native';
import {createSelector} from '@reduxjs/toolkit';
import {Button, FlatList, Menu, Pressable} from 'native-base';
import {Button, FlatList} from 'native-base';

import {
Project,
Expand All @@ -47,7 +48,6 @@ import {ConfirmModal} from 'terraso-mobile-client/components/modals/ConfirmModal
import {
Box,
Column,
Row,
Text,
} from 'terraso-mobile-client/components/NativeBaseAdapters';
import {RestrictByProjectRole} from 'terraso-mobile-client/components/RestrictByRole';
Expand All @@ -63,30 +63,16 @@ import {AppState, useDispatch, useSelector} from 'terraso-mobile-client/store';
import {theme} from 'terraso-mobile-client/theme';
import {searchText} from 'terraso-mobile-client/util';

type SiteMenuProps = {
text: string;
onPress?: () => void;
};

const SiteMenuItem = ({text, onPress}: SiteMenuProps) => {
return (
<Menu.Item>
<Pressable onPress={onPress}>
<Row flexDirection="row" space={2} alignItems="center">
<Text>{text}</Text>
</Row>
</Pressable>
</Menu.Item>
);
};

type SiteProps = {
site: Site;
};

const SiteMenu = ({site}: SiteProps) => {
const {t} = useTranslation();
const dispatch = useDispatch();
const [visible, setVisible] = useState(false);
const openMenu = () => setVisible(true);
const closeMenu = () => setVisible(false);

const deleteSiteCallback = async () => {
await dispatch(deleteSite(site));
Expand All @@ -100,32 +86,42 @@ const SiteMenu = ({site}: SiteProps) => {

return (
<Menu
closeOnSelect={true}
trigger={triggerProps => (
<IconButton name="more-vert" {...triggerProps} />
)}>
contentStyle={{
backgroundColor: theme.colors.background.default,
}}
visible={visible}
onDismiss={closeMenu}
anchor={<IconButton onPress={openMenu} name="more-vert" />}>
<ConfirmModal
trigger={onOpen => (
<SiteMenuItem
text={t('projects.sites.remove_site')}
onPress={onOpen}
/>
)}
trigger={onOpen => {
return (
<Menu.Item
title={t('projects.sites.remove_site')}
onPress={onOpen}
titleStyle={MENU_ITEM_STYLE}
/>
);
}}
title={t('projects.sites.remove_site_modal.title')}
body={t('projects.sites.remove_site_modal.body', {siteName: site.name})}
body={t('projects.sites.remove_site_modal.body', {
siteName: site.name,
})}
actionName={t('projects.sites.remove_site_modal.action_name')}
handleConfirm={removeSiteFromProjectCallback}
/>

<ConfirmModal
trigger={onOpen => (
<SiteMenuItem
<Menu.Item
title={t('projects.sites.delete_site')}
onPress={onOpen}
text={t('projects.sites.delete_site')}
titleStyle={MENU_ITEM_STYLE}
/>
)}
title={t('projects.sites.delete_site_modal.title')}
body={t('projects.sites.delete_site_modal.body', {siteName: site.name})}
body={t('projects.sites.delete_site_modal.body', {
siteName: site.name,
})}
actionName={t('projects.sites.delete_site_modal.action_name')}
handleConfirm={deleteSiteCallback}
/>
Expand Down Expand Up @@ -289,3 +285,7 @@ export function ProjectSitesScreen({
</Column>
);
}

const MENU_ITEM_STYLE = {
fontSize: 18,
};

0 comments on commit bebbfe6

Please sign in to comment.