mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
make sure menu does not rerender on swipe
This commit is contained in:
@@ -1,13 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {ScrollView, StatusBar, View} from 'react-native';
|
import {ScrollView, View} from 'react-native';
|
||||||
|
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
||||||
import {useTracked} from '../../provider';
|
import {useTracked} from '../../provider';
|
||||||
import {Actions} from '../../provider/Actions';
|
import {Actions} from '../../provider/Actions';
|
||||||
import {ColorSection} from './ColorSection';
|
import {DDS} from '../../services/DeviceDetection';
|
||||||
import {MenuListItem} from './MenuListItem';
|
|
||||||
import {TagsSection} from './TagsSection';
|
|
||||||
import {UserSection} from './UserSection';
|
|
||||||
import Seperator from '../Seperator';
|
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
||||||
import {
|
import {
|
||||||
ACCENT,
|
ACCENT,
|
||||||
COLOR_SCHEME,
|
COLOR_SCHEME,
|
||||||
@@ -15,19 +11,32 @@ import {
|
|||||||
COLOR_SCHEME_LIGHT,
|
COLOR_SCHEME_LIGHT,
|
||||||
setColorScheme,
|
setColorScheme,
|
||||||
} from '../../utils/Colors';
|
} from '../../utils/Colors';
|
||||||
import {MenuItemsList} from "../../utils/index"
|
import {MenuItemsList} from '../../utils/index';
|
||||||
import {MMKV} from '../../utils/mmkv';
|
import {MMKV} from '../../utils/mmkv';
|
||||||
|
import {SIZE} from '../../utils/SizeUtils';
|
||||||
|
import Seperator from '../Seperator';
|
||||||
|
import Heading from '../Typography/Heading';
|
||||||
|
import Paragraph from '../Typography/Paragraph';
|
||||||
|
import {ColorSection} from './ColorSection';
|
||||||
|
import {MenuListItem} from './MenuListItem';
|
||||||
|
import {TagsSection} from './TagsSection';
|
||||||
|
import {UserSection} from './UserSection';
|
||||||
|
|
||||||
export const Menu = ({close = () => {}, hide, noTextMode = false}) => {
|
export const Menu = React.memo(
|
||||||
|
() => {
|
||||||
const [state, dispatch] = useTracked();
|
const [state, dispatch] = useTracked();
|
||||||
const {colors} = state;
|
const {colors} = state;
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
|
const noTextMode = DDS.isTab && !DDS.isSmallTab;
|
||||||
function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
|
function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
|
||||||
let newColors = setColorScheme(colors, accent);
|
let newColors = setColorScheme(colors, accent);
|
||||||
dispatch({type: Actions.THEME, colors: newColors});
|
dispatch({type: Actions.THEME, colors: newColors});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
console.log('rerendering drawer');
|
||||||
|
});
|
||||||
|
|
||||||
const BottomItemsList = [
|
const BottomItemsList = [
|
||||||
{
|
{
|
||||||
name: 'Night mode',
|
name: 'Night mode',
|
||||||
@@ -56,7 +65,6 @@ export const Menu = ({close = () => {}, hide, noTextMode = false}) => {
|
|||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
height: '100%',
|
height: '100%',
|
||||||
opacity: hide ? 0 : 1,
|
|
||||||
width: '100%',
|
width: '100%',
|
||||||
backgroundColor: colors.bg,
|
backgroundColor: colors.bg,
|
||||||
paddingTop: insets.top,
|
paddingTop: insets.top,
|
||||||
@@ -67,9 +75,9 @@ export const Menu = ({close = () => {}, hide, noTextMode = false}) => {
|
|||||||
alwaysBounceVertical={false}
|
alwaysBounceVertical={false}
|
||||||
contentContainerStyle={{
|
contentContainerStyle={{
|
||||||
minHeight: '50%',
|
minHeight: '50%',
|
||||||
|
flexGrow: 1,
|
||||||
}}
|
}}
|
||||||
showsVerticalScrollIndicator={false}>
|
showsVerticalScrollIndicator={false}>
|
||||||
|
|
||||||
{MenuItemsList.map((item, index) => (
|
{MenuItemsList.map((item, index) => (
|
||||||
<MenuListItem
|
<MenuListItem
|
||||||
testID={item.name}
|
testID={item.name}
|
||||||
@@ -82,6 +90,24 @@ export const Menu = ({close = () => {}, hide, noTextMode = false}) => {
|
|||||||
|
|
||||||
{noTextMode ? null : <TagsSection />}
|
{noTextMode ? null : <TagsSection />}
|
||||||
<ColorSection noTextMode={noTextMode} />
|
<ColorSection noTextMode={noTextMode} />
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexGrow: 1,
|
||||||
|
paddingHorizontal: '10%',
|
||||||
|
}}>
|
||||||
|
<Heading style={{marginBottom: 2.5}} size={SIZE.sm}>
|
||||||
|
Your Pins
|
||||||
|
</Heading>
|
||||||
|
<Paragraph
|
||||||
|
style={{textAlign: 'center'}}
|
||||||
|
color={colors.icon}
|
||||||
|
size={SIZE.xs}>
|
||||||
|
You have not pinned anything yet. You can pin notebook topics and
|
||||||
|
tags here.
|
||||||
|
</Paragraph>
|
||||||
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
@@ -113,4 +139,6 @@ export const Menu = ({close = () => {}, hide, noTextMode = false}) => {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
},
|
||||||
|
() => true,
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import * as React from "react";
|
import * as React from 'react';
|
||||||
import {eSubscribeEvent, eUnSubscribeEvent} from "../services/EventManager";
|
import {eSubscribeEvent, eUnSubscribeEvent} from '../services/EventManager';
|
||||||
import {eCloseSideMenu, eOpenSideMenu} from "../utils/Events";
|
import {eCloseSideMenu, eOpenSideMenu} from '../utils/Events';
|
||||||
import {NavigationContainer} from "@react-navigation/native";
|
import {NavigationContainer} from '@react-navigation/native';
|
||||||
import {sideMenuRef} from "../utils/Refs";
|
import {sideMenuRef} from '../utils/Refs';
|
||||||
import {Dimensions} from "react-native";
|
import {Dimensions} from 'react-native';
|
||||||
import {NavigatorStack} from "./NavigatorStack";
|
import {NavigatorStack} from './NavigatorStack';
|
||||||
import {Menu} from "../components/Menu";
|
import {Menu} from '../components/Menu';
|
||||||
import NavigationService from "../services/Navigation";
|
import NavigationService from '../services/Navigation';
|
||||||
import {createDrawerNavigator} from '@react-navigation/drawer';
|
import {createDrawerNavigator} from '@react-navigation/drawer';
|
||||||
import {DDS} from "../services/DeviceDetection";
|
import {DDS} from '../services/DeviceDetection';
|
||||||
|
|
||||||
const Drawer = createDrawerNavigator();
|
const Drawer = createDrawerNavigator();
|
||||||
|
|
||||||
@@ -39,7 +39,8 @@ export const NavigationStack = ({component = NavigatorStack}) => {
|
|||||||
swipeEnabled: locked ? false : true,
|
swipeEnabled: locked ? false : true,
|
||||||
}}
|
}}
|
||||||
drawerStyle={{
|
drawerStyle={{
|
||||||
width: DDS.isTab && !DDS.isSmallTab
|
width:
|
||||||
|
DDS.isTab && !DDS.isSmallTab
|
||||||
? Dimensions.get('window').width * 0.05
|
? Dimensions.get('window').width * 0.05
|
||||||
: DDS.isSmallTab
|
: DDS.isSmallTab
|
||||||
? '40%'
|
? '40%'
|
||||||
@@ -56,13 +57,10 @@ export const NavigationStack = ({component = NavigatorStack}) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const DrawerComponent = (props) => {
|
|
||||||
|
|
||||||
|
const DrawerComponent = () => {
|
||||||
return (
|
return (
|
||||||
<Menu
|
<Menu/>
|
||||||
menuProps={props}
|
|
||||||
hide={false}
|
|
||||||
noTextMode={DDS.isTab && !DDS.isSmallTab}
|
|
||||||
close={() => NavigationService.closeDrawer()}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user