mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
apply some optimizations
This commit is contained in:
@@ -54,7 +54,7 @@ export const ContainerBottomButton = ({
|
|||||||
right: 12,
|
right: 12,
|
||||||
bottom:
|
bottom:
|
||||||
Platform.OS === 'ios' && insets.bottom !== 0
|
Platform.OS === 'ios' && insets.bottom !== 0
|
||||||
? insets.bottom - 25
|
? Platform.isPad ? insets.bottom - 12 : insets.bottom - 24
|
||||||
: insets.bottom + 12,
|
: insets.bottom + 12,
|
||||||
zIndex: 10,
|
zIndex: 10,
|
||||||
transform: [
|
transform: [
|
||||||
|
|||||||
@@ -7,27 +7,9 @@ import Navigation from '../../services/Navigation';
|
|||||||
import {SIZE} from '../../utils/SizeUtils';
|
import {SIZE} from '../../utils/SizeUtils';
|
||||||
import {ActionIcon} from '../ActionIcon';
|
import {ActionIcon} from '../ActionIcon';
|
||||||
|
|
||||||
export const HeaderLeftMenu = () => {
|
export const HeaderLeftMenu = ({currentScreen,headerMenuState}) => {
|
||||||
const [state] = useTracked();
|
const [state] = useTracked();
|
||||||
const {colors, deviceMode} = state;
|
const {colors, deviceMode} = state;
|
||||||
const [headerTextState, setHeaderTextState] = useState(
|
|
||||||
Navigation.getHeaderState(),
|
|
||||||
);
|
|
||||||
|
|
||||||
const currentScreen = headerTextState.currentScreen;
|
|
||||||
const headerMenuState = headerTextState.verticalMenu;
|
|
||||||
|
|
||||||
const onHeaderStateChange = (event) => {
|
|
||||||
if (!event) return;
|
|
||||||
setHeaderTextState(event);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
|
|
||||||
return () => {
|
|
||||||
eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const onLeftButtonPress = () => {
|
const onLeftButtonPress = () => {
|
||||||
if (headerMenuState) {
|
if (headerMenuState) {
|
||||||
|
|||||||
@@ -10,25 +10,9 @@ import {SIZE} from '../../utils/SizeUtils';
|
|||||||
import {ActionIcon} from '../ActionIcon';
|
import {ActionIcon} from '../ActionIcon';
|
||||||
import {Button} from '../Button';
|
import {Button} from '../Button';
|
||||||
|
|
||||||
export const HeaderRightMenu = () => {
|
export const HeaderRightMenu = ({currentScreen}) => {
|
||||||
const [state] = useTracked();
|
const [state] = useTracked();
|
||||||
const {colors, containerBottomButton, syncing} = state;
|
const {colors, containerBottomButton, syncing} = state;
|
||||||
const [headerTextState, setHeaderTextState] = useState(
|
|
||||||
Navigation.getHeaderState(),
|
|
||||||
);
|
|
||||||
const currentScreen = headerTextState.currentScreen;
|
|
||||||
|
|
||||||
const onHeaderStateChange = (event) => {
|
|
||||||
if (!event) return;
|
|
||||||
setHeaderTextState(event);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
|
|
||||||
return () => {
|
|
||||||
eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.rightBtnContainer}>
|
<View style={styles.rightBtnContainer}>
|
||||||
|
|||||||
@@ -11,20 +11,9 @@ const opacity = new Animated.Value(DDS.isLargeTablet() ? 1 : 0);
|
|||||||
|
|
||||||
let scrollPostions = {};
|
let scrollPostions = {};
|
||||||
|
|
||||||
export const HeaderTitle = () => {
|
export const HeaderTitle = ({heading,headerColor}) => {
|
||||||
const [state] = useTracked();
|
const [state] = useTracked();
|
||||||
const {colors} = state;
|
const {colors} = state;
|
||||||
const [headerTextState, setHeaderTextState] = useState(Navigation.getHeaderState());
|
|
||||||
|
|
||||||
const onHeaderStateChange = (event) => {
|
|
||||||
setHeaderTextState(event);
|
|
||||||
};
|
|
||||||
useEffect(() => {
|
|
||||||
eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
|
|
||||||
return () => {
|
|
||||||
eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
|
|
||||||
const onScroll = async (y) => {
|
const onScroll = async (y) => {
|
||||||
@@ -55,7 +44,7 @@ export const HeaderTitle = () => {
|
|||||||
} else {
|
} else {
|
||||||
opacity.setValue(0);
|
opacity.setValue(0);
|
||||||
}
|
}
|
||||||
scrollPostions[headerTextState?.heading] = y;
|
scrollPostions[heading] = y;
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -63,21 +52,21 @@ export const HeaderTitle = () => {
|
|||||||
return () => {
|
return () => {
|
||||||
eUnSubscribeEvent(eScrollEvent, onScroll);
|
eUnSubscribeEvent(eScrollEvent, onScroll);
|
||||||
};
|
};
|
||||||
}, [headerTextState?.heading]);
|
}, [heading]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Animated.View
|
<Animated.View
|
||||||
style={{
|
style={{
|
||||||
opacity: DDS.isTab ? 1 : opacity,
|
opacity: DDS.isTab ? 1 : opacity,
|
||||||
}}>
|
}}>
|
||||||
<Heading color={headerTextState?.color}>
|
<Heading color={headerColor}>
|
||||||
<Heading color={colors.accent}>
|
<Heading color={colors.accent}>
|
||||||
{headerTextState?.heading.slice(0, 1) === '#' ? '#' : null}
|
{heading.slice(0, 1) === '#' ? '#' : null}
|
||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
{headerTextState?.heading.slice(0, 1) === '#'
|
{heading.slice(0, 1) === '#'
|
||||||
? headerTextState?.heading.slice(1)
|
? heading.slice(1)
|
||||||
: headerTextState?.heading}
|
: heading}
|
||||||
</Heading>
|
</Heading>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export const Header = ({root}) => {
|
|||||||
);
|
);
|
||||||
const currentScreen = headerTextState.currentScreen;
|
const currentScreen = headerTextState.currentScreen;
|
||||||
|
|
||||||
const onHeaderStateChange = (event) => {
|
const onHeaderStateChange = event => {
|
||||||
if (!event) return;
|
if (!event) return;
|
||||||
setHeaderTextState(event);
|
setHeaderTextState(event);
|
||||||
};
|
};
|
||||||
@@ -36,7 +36,7 @@ export const Header = ({root}) => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onScroll = (y) => {
|
const onScroll = y => {
|
||||||
if (y > 150) {
|
if (y > 150) {
|
||||||
setHide(false);
|
setHide(false);
|
||||||
} else {
|
} else {
|
||||||
@@ -65,29 +65,40 @@ export const Header = ({root}) => {
|
|||||||
},
|
},
|
||||||
]}>
|
]}>
|
||||||
<View style={styles.leftBtnContainer}>
|
<View style={styles.leftBtnContainer}>
|
||||||
<HeaderLeftMenu />
|
<HeaderLeftMenu
|
||||||
|
headerMenuState={headerTextState.verticalMenu}
|
||||||
|
currentScreen={currentScreen}
|
||||||
|
/>
|
||||||
|
|
||||||
{(Platform.OS === 'android' ||
|
{(Platform.OS === 'android' || Platform.isPad) &&
|
||||||
Platform.isPad) && currentScreen !== 'Search' ? (
|
currentScreen !== 'Search' ? (
|
||||||
<HeaderTitle root={root} />
|
<HeaderTitle
|
||||||
|
headerColor={headerTextState.color}
|
||||||
|
heading={headerTextState.heading}
|
||||||
|
currentScreen={currentScreen}
|
||||||
|
root={root}
|
||||||
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
{Platform.OS !== 'android' &&
|
{Platform.OS !== 'android' &&
|
||||||
!Platform.isPad &&
|
!Platform.isPad &&
|
||||||
currentScreen !== 'Search' ? (
|
currentScreen !== 'Search' ? (
|
||||||
<HeaderTitle root={root} />
|
<HeaderTitle
|
||||||
|
headerColor={headerTextState.color}
|
||||||
|
heading={headerTextState.heading}
|
||||||
|
currentScreen={currentScreen}
|
||||||
|
root={root}
|
||||||
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{currentScreen === 'Search' ? (
|
{currentScreen === 'Search' ? (
|
||||||
|
<>
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
width: '80%',
|
width: '80%',
|
||||||
}}>
|
}}>
|
||||||
<SearchInput />
|
<SearchInput />
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
|
||||||
|
|
||||||
{currentScreen === 'Search' ? (
|
|
||||||
<View style={[styles.rightBtnContainer, {right: 6}]}>
|
<View style={[styles.rightBtnContainer, {right: 6}]}>
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
@@ -99,8 +110,9 @@ export const Header = ({root}) => {
|
|||||||
style={styles.rightBtn}
|
style={styles.rightBtn}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<HeaderRightMenu />
|
<HeaderRightMenu currentScreen={currentScreen} />
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -67,10 +67,16 @@ const SimpleList = ({
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
sleep(100).then(() => setLoaded(true));
|
setTimeout(() => {
|
||||||
|
setLoaded(true)
|
||||||
|
},50);
|
||||||
}
|
}
|
||||||
}, [listData, deviceMode, loading]);
|
}, [listData, deviceMode, loading]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("rerendering");
|
||||||
|
})
|
||||||
|
|
||||||
const _onRefresh = async () => {
|
const _onRefresh = async () => {
|
||||||
await Sync.run();
|
await Sync.run();
|
||||||
if (refreshCallback) {
|
if (refreshCallback) {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ const forSlide = ({current, next, inverted, layouts: {screen}}) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const screenOptionsForAnimation = {
|
const screenOptionsForAnimation = {
|
||||||
animationEnabled: true,
|
animationEnabled: false,
|
||||||
cardStyleInterpolator: forSlide,
|
cardStyleInterpolator: forSlide,
|
||||||
gestureEnabled: true,
|
gestureEnabled: true,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ function setHeaderState(name, params, item) {
|
|||||||
currentScreen = name;
|
currentScreen = name;
|
||||||
headerState.currentScreen = name;
|
headerState.currentScreen = name;
|
||||||
headerState.verticalMenu = params.menu;
|
headerState.verticalMenu = params.menu;
|
||||||
|
|
||||||
if (headerState) {
|
if (headerState) {
|
||||||
eSendEvent('onHeaderStateChange', {...headerState});
|
eSendEvent('onHeaderStateChange', {...headerState});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,6 @@ export const Folders = ({route, navigation}) => {
|
|||||||
let ranAfterInteractions = false;
|
let ranAfterInteractions = false;
|
||||||
|
|
||||||
const onFocus = useCallback(() => {
|
const onFocus = useCallback(() => {
|
||||||
if (!ranAfterInteractions) {
|
|
||||||
ranAfterInteractions = true;
|
|
||||||
runAfterInteractions();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pageIsLoaded) {
|
if (!pageIsLoaded) {
|
||||||
pageIsLoaded = true;
|
pageIsLoaded = true;
|
||||||
return;
|
return;
|
||||||
@@ -39,7 +34,10 @@ export const Folders = ({route, navigation}) => {
|
|||||||
id: 'notebooks_navigation',
|
id: 'notebooks_navigation',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
if (!ranAfterInteractions) {
|
||||||
|
ranAfterInteractions = true;
|
||||||
|
runAfterInteractions();
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const runAfterInteractions = () => {
|
const runAfterInteractions = () => {
|
||||||
@@ -48,8 +46,8 @@ export const Folders = ({route, navigation}) => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
Navigation.routeNeedsUpdate('Notebooks', () => {
|
Navigation.routeNeedsUpdate('Notebooks', () => {
|
||||||
dispatch({type:Actions.NOTEBOOKS})
|
dispatch({type: Actions.NOTEBOOKS});
|
||||||
})
|
});
|
||||||
|
|
||||||
eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'in'});
|
eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'in'});
|
||||||
updateSearch();
|
updateSearch();
|
||||||
|
|||||||
@@ -32,12 +32,11 @@ export const Notebook = ({route, navigation}) => {
|
|||||||
params.notebook = notebook;
|
params.notebook = notebook;
|
||||||
params.title = params.notebook.title;
|
params.title = params.notebook.title;
|
||||||
setTopics(notebook.topics);
|
setTopics(notebook.topics);
|
||||||
sleep(10).then((r) => {
|
setTimeout(() => {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
});
|
},10)
|
||||||
|
|
||||||
Navigation.routeNeedsUpdate('Notebook', () => {
|
Navigation.routeNeedsUpdate('Notebook', () => {
|
||||||
onLoad();
|
onLoad();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import {
|
|||||||
refreshNotesPage,
|
refreshNotesPage,
|
||||||
} from '../../utils/Events';
|
} from '../../utils/Events';
|
||||||
import {tabBarRef} from '../../utils/Refs';
|
import {tabBarRef} from '../../utils/Refs';
|
||||||
import {sleep} from '../../utils/TimeUtils';
|
|
||||||
|
|
||||||
export const Notes = ({route, navigation}) => {
|
export const Notes = ({route, navigation}) => {
|
||||||
const [state, dispatch] = useTracked();
|
const [state, dispatch] = useTracked();
|
||||||
@@ -56,9 +55,9 @@ export const Notes = ({route, navigation}) => {
|
|||||||
}
|
}
|
||||||
setNotes(_notes);
|
setNotes(_notes);
|
||||||
if (localLoad) {
|
if (localLoad) {
|
||||||
sleep(10).then((r) => {
|
setTimeout(() => {
|
||||||
setLocalLoad(false);
|
setLocalLoad(false);
|
||||||
});
|
}, 10);
|
||||||
}
|
}
|
||||||
if (params.menu) {
|
if (params.menu) {
|
||||||
navigation.setOptions({
|
navigation.setOptions({
|
||||||
@@ -72,6 +71,7 @@ export const Notes = ({route, navigation}) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
updateSearch();
|
updateSearch();
|
||||||
|
if (DDS.isLargeTablet()) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: Actions.CONTAINER_BOTTOM_BUTTON,
|
type: Actions.CONTAINER_BOTTOM_BUTTON,
|
||||||
state: {
|
state: {
|
||||||
@@ -79,6 +79,8 @@ export const Notes = ({route, navigation}) => {
|
|||||||
color: params.type == 'color' ? COLORS_NOTE[params.title] : null,
|
color: params.type == 'color' ? COLORS_NOTE[params.title] : null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ranAfterInteractions = false;
|
ranAfterInteractions = false;
|
||||||
}, time);
|
}, time);
|
||||||
};
|
};
|
||||||
@@ -118,7 +120,7 @@ export const Notes = ({route, navigation}) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const init = (data) => {
|
const init = data => {
|
||||||
if (data) {
|
if (data) {
|
||||||
setLocalLoad(true);
|
setLocalLoad(true);
|
||||||
params = data;
|
params = data;
|
||||||
|
|||||||
Reference in New Issue
Block a user