Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

prevent unnecessary renders

ammarahm-ede9dee651f9a1
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index 0b7a9794c..c89939c2e 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -39,438 +39,443 @@ let timer = null;
let note = {};
const Editor = ({navigation}) => {
- // Global State
- const {colors} = useAppContext();
-
- // Local State
-
- const [dialog, setDialog] = useState(false);
- const [isOpen, setOpen] = useState(false);
- const [sidebar, setSidebar] = useState(DDS.isTab ? true : false);
- const [vaultDialog, setVaultDialog] = useState(false);
- const [unlock, setUnlock] = useState(false);
- const [visible, setVisible] = useState(false);
- const [noteProps, setNoteProps] = useState({
- tags: [],
- locked: false,
- pinned: false,
- favorite: false,
- colors: [],
- });
-
- // VARIABLES
-
- let willRefresh = false;
- let customNote = null;
- let actionSheet;
- let show;
- // FUNCTIONS
-
- const post = value => EditorWebView.postMessage(value);
-
- const onChange = data => {
- if (data !== '') {
- content = JSON.parse(data);
- }
- };
-
- const saveNote = async (noteProps = {}, lockNote = true) => {
- if (!content) {
- content = {
- text: '',
- delta: null,
- };
- }
-
- timestamp = await db.addNote({
- ...noteProps,
- title,
- content: {
- text: content.text,
- delta: content.delta,
- },
- dateCreated: timestamp,
+ if (!isFocused) {
+ console.log('block rerender');
+ return <></>;
+ } else {
+ // Global State
+ const {colors} = useAppContext();
+
+ // Local State
+
+ const [dialog, setDialog] = useState(false);
+ const [isOpen, setOpen] = useState(false);
+ const [sidebar, setSidebar] = useState(DDS.isTab ? true : false);
+ const [vaultDialog, setVaultDialog] = useState(false);
+ const [unlock, setUnlock] = useState(false);
+ const [visible, setVisible] = useState(false);
+ const [noteProps, setNoteProps] = useState({
+ tags: [],
+ locked: false,
+ pinned: false,
+ favorite: false,
+ colors: [],
});
- if (lockNote && noteProps.locked) {
- db.lockNote(timestamp, 'password');
- }
- };
-
- const onWebViewLoad = () => {
- post(JSON.stringify(colors));
- if (navigation.state.params && navigation.state.params.note) {
- note = navigation.state.params.note;
- updateEditor();
- }
- };
-
- const updateEditor = () => {
- let props = {
- tags: note.tags,
- colors: note.colors,
- pinned: note.pinned,
- favorite: note.favorite,
- locked: note.locked,
+ // VARIABLES
+
+ let willRefresh = false;
+ let customNote = null;
+ let actionSheet;
+ let show;
+ // FUNCTIONS
+
+ const post = value => EditorWebView.postMessage(value);
+
+ const onChange = data => {
+ if (data !== '') {
+ content = JSON.parse(data);
+ }
};
- setNoteProps({...props});
- post(JSON.stringify(note.content.delta));
- setTimeout(() => {
- title = note.title;
- titleRef.setNativeProps({
- text: title,
+ const saveNote = async (noteProps = {}, lockNote = true) => {
+ if (!content) {
+ content = {
+ text: '',
+ delta: null,
+ };
+ }
+
+ timestamp = await db.addNote({
+ ...noteProps,
+ title,
+ content: {
+ text: content.text,
+ delta: content.delta,
+ },
+ dateCreated: timestamp,
});
- timestamp = note.dateCreated;
- content = note.content;
- }, 200);
- };
-
- const onTitleTextChange = value => {
- title = value;
- };
-
- const onMenuHide = () => {
- if (show) {
- if (show === 'lock') {
- if (unlock) {
- setUnlock(false);
+
+ if (lockNote && noteProps.locked) {
+ db.lockNote(timestamp, 'password');
+ }
+ };
+
+ const onWebViewLoad = () => {
+ post(JSON.stringify(colors));
+ if (navigation.state.params && navigation.state.params.note) {
+ note = navigation.state.params.note;
+ updateEditor();
+ }
+ };
+
+ const updateEditor = () => {
+ let props = {
+ tags: note.tags,
+ colors: note.colors,
+ pinned: note.pinned,
+ favorite: note.favorite,
+ locked: note.locked,
+ };
+ setNoteProps({...props});
+
+ post(JSON.stringify(note.content.delta));
+ setTimeout(() => {
+ title = note.title;
+ titleRef.setNativeProps({
+ text: title,
+ });
+ timestamp = note.dateCreated;
+ content = note.content;
+ }, 200);
+ };
+
+ const onTitleTextChange = value => {
+ title = value;
+ };
+
+ const onMenuHide = () => {
+ if (show) {
+ if (show === 'lock') {
+ if (unlock) {
+ setUnlock(false);
+ }
+ setVaultDialog(true);
+ } else if (show === 'unlock') {
+ setUnlock(true);
+ setVaultDialog(true);
+ } else if (show == 'delete') {
+ setVisible(true);
}
- setVaultDialog(true);
- } else if (show === 'unlock') {
- setUnlock(true);
- setVaultDialog(true);
- } else if (show == 'delete') {
- setVisible(true);
}
- }
- };
-
- const deleteItem = async () => {
- await db.deleteNotes([note]);
- ToastEvent.show('Note moved to trash', 'success', 3000);
- setVisible(false);
- navigation.goBack();
- };
-
- const _renderEditor = () => {
- return (
- <KeyboardAvoidingView
- behavior={Platform.OS === 'ios' ? 'padding' : null}
- style={{height: '100%'}}>
- <View
- style={{
- height: '100%',
- }}>
+ };
+
+ const deleteItem = async () => {
+ await db.deleteNotes([note]);
+ ToastEvent.show('Note moved to trash', 'success', 3000);
+ setVisible(false);
+ navigation.goBack();
+ };
+
+ const _renderEditor = () => {
+ return (
+ <KeyboardAvoidingView
+ behavior={Platform.OS === 'ios' ? 'padding' : null}
+ style={{height: '100%'}}>
<View
style={{
- flexDirection: 'row',
- justifyContent: 'flex-start',
- alignItems: 'center',
- paddingHorizontal: 12,
- width: '100%',
- alignSelf: 'center',
- height: 50,
-
- marginTop: Platform.OS == 'ios' ? 0 : StatusBar.currentHeight,
+ height: '100%',
}}>
- <TouchableOpacity
- onPress={() => {
- setDialog(true);
- }}
+ <View
style={{
- width: '12.5%',
- height: 40,
- justifyContent: 'center',
- alignItems: 'flex-start',
+ flexDirection: 'row',
+ justifyContent: 'flex-start',
+ alignItems: 'center',
+ paddingHorizontal: 12,
+ width: '100%',
+ alignSelf: 'center',
+ height: 50,
+
+ marginTop: Platform.OS == 'ios' ? 0 : StatusBar.currentHeight,
}}>
- <Icon
+ <TouchableOpacity
+ onPress={() => {
+ setDialog(true);
+ }}
style={{
- marginLeft: -7,
+ width: '12.5%',
+ height: 40,
+ justifyContent: 'center',
+ alignItems: 'flex-start',
+ }}>
+ <Icon
+ style={{
+ marginLeft: -7,
+ }}
+ name="chevron-left"
+ color={colors.icon}
+ size={SIZE.xxxl - 3}
+ />
+ </TouchableOpacity>
+
+ <TextInput
+ placeholder="Untitled Note"
+ ref={ref => (titleRef = ref)}
+ placeholderTextColor={colors.icon}
+ defaultValue={note && note.title ? note.title : title}
+ style={{
+ width: '75%',
+ fontFamily: WEIGHT.bold,
+ fontSize: SIZE.xl,
+ color: colors.pri,
+ maxWidth: '75%',
+ paddingVertical: 0,
+ paddingHorizontal: 0,
}}
- name="chevron-left"
- color={colors.icon}
- size={SIZE.xxxl - 3}
+ onChangeText={onTitleTextChange}
+ onSubmitEditing={saveNote}
/>
- </TouchableOpacity>
- <TextInput
- placeholder="Untitled Note"
- ref={ref => (titleRef = ref)}
- placeholderTextColor={colors.icon}
- defaultValue={note && note.title ? note.title : title}
+ <TouchableOpacity
+ onPress={() => {
+ DDS.isTab
+ ? setSidebar(!sidebar)
+ : actionSheet._setModalVisible();
+ }}
+ style={{
+ width: '12.5%',
+ height: 40,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
+ }}>
+ <Icon
+ name="more-horizontal"
+ color={colors.icon}
+ size={SIZE.xxxl}
+ />
+ </TouchableOpacity>
+ </View>
+
+ <WebView
+ ref={ref => (EditorWebView = ref)}
+ onError={error => console.log(error)}
+ onLoad={onWebViewLoad}
+ javaScriptEnabled
+ onShouldStartLoadWithRequest={request => {
+ if (request.url.includes('https')) {
+ Linking.openURL(request.url);
+ return false;
+ } else {
+ return true;
+ }
+ }}
+ renderLoading={() => (
+ <View
+ style={{
+ width: '100%',
+ height: '100%',
+ backgroundColor: 'transparent',
+ }}
+ />
+ )}
+ cacheEnabled={true}
+ cacheMode="LOAD_CACHE_ELSE_NETWORK"
+ domStorageEnabled
+ scrollEnabled={false}
+ bounces={true}
+ scalesPageToFit={true}
+ source={
+ Platform.OS === 'ios'
+ ? require('./web/texteditor.html')
+ : {
+ uri: 'file:///android_asset/texteditor.html',
+ baseUrl: 'baseUrl:"file:///android_asset/',
+ }
+ }
style={{
- width: '75%',
- fontFamily: WEIGHT.bold,
- fontSize: SIZE.xl,
- color: colors.pri,
- maxWidth: '75%',
- paddingVertical: 0,
- paddingHorizontal: 0,
+ height: '100%',
+ maxHeight: '100%',
+ backgroundColor: 'transparent',
}}
- onChangeText={onTitleTextChange}
- onSubmitEditing={saveNote}
- />
-
- <TouchableOpacity
- onPress={() => {
- DDS.isTab
- ? setSidebar(!sidebar)
- : actionSheet._setModalVisible();
+ onMessage={evt => {
+ if (evt.nativeEvent.data !== '') {
+ clearTimeout(timer);
+ timer = null;
+ onChange(evt.nativeEvent.data);
+ timer = setTimeout(() => {
+ saveNote(noteProps, true);
+ console.log('saved');
+ }, 1000);
+ }
}}
- style={{
- width: '12.5%',
- height: 40,
- justifyContent: 'center',
- alignItems: 'flex-end',
- }}>
- <Icon
- name="more-horizontal"
- color={colors.icon}
- size={SIZE.xxxl}
- />
- </TouchableOpacity>
+ />
</View>
+ </KeyboardAvoidingView>
+ );
+ };
- <WebView
- ref={ref => (EditorWebView = ref)}
- onError={error => console.log(error)}
- onLoad={onWebViewLoad}
- javaScriptEnabled
- onShouldStartLoadWithRequest={request => {
- if (request.url.includes('https')) {
- Linking.openURL(request.url);
- return false;
- } else {
- return true;
- }
- }}
- renderLoading={() => (
- <View
- style={{
- width: '100%',
- height: '100%',
- backgroundColor: 'transparent',
- }}
- />
- )}
- cacheEnabled={true}
- cacheMode="LOAD_CACHE_ELSE_NETWORK"
- domStorageEnabled
- scrollEnabled={false}
- bounces={true}
- scalesPageToFit={true}
- source={
- Platform.OS === 'ios'
- ? require('./web/texteditor.html')
- : {
- uri: 'file:///android_asset/texteditor.html',
- baseUrl: 'baseUrl:"file:///android_asset/',
- }
- }
- style={{
- height: '100%',
- maxHeight: '100%',
- backgroundColor: 'transparent',
+ // EFFECTS
+
+ useEffect(() => {
+ let handleBack = BackHandler.addEventListener('hardwareBackPress', () => {
+ setDialog(true);
+ return true;
+ });
+ return () => {
+ handleBack.remove();
+ handleBack = null;
+ title = null;
+ content = null;
+ timer = null;
+ timestamp = null;
+ };
+ }, []);
+
+ useEffect(() => {
+ SideMenuEvent.close();
+ SideMenuEvent.disable();
+ return () => {
+ DDS.isTab ? SideMenuEvent.open() : null;
+ SideMenuEvent.enable();
+ };
+ });
+
+ useEffect(() => {
+ EditorWebView.reload();
+ }, [colors]);
+
+ return DDS.isTab ? (
+ <View
+ style={{
+ flexDirection: 'row',
+ width: '100%',
+ }}>
+ <AnimatedSafeAreaView
+ transition={['backgroundColor', 'width']}
+ duration={300}
+ style={{
+ height: '100%',
+ backgroundColor: colors.bg,
+ width: sidebar ? '70%' : '100%',
+ }}>
+ <Dialog
+ title="Close Editor"
+ visible={dialog}
+ icon="x"
+ paragraph="Are you sure you want to close editor?"
+ close={() => {
+ setDialog(false);
}}
- onMessage={evt => {
- if (evt.nativeEvent.data !== '') {
- clearTimeout(timer);
- timer = null;
- onChange(evt.nativeEvent.data);
- timer = setTimeout(() => {
- saveNote(noteProps, true);
- console.log('saved');
- }, 1000);
- }
+ positivePress={() => {
+ setTimeout(() => {
+ navigation.goBack();
+ setDialog(false);
+ }, 1000);
}}
/>
- </View>
- </KeyboardAvoidingView>
- );
- };
- // EFFECTS
-
- useEffect(() => {
- let handleBack = BackHandler.addEventListener('hardwareBackPress', () => {
- setDialog(true);
- return true;
- });
- return () => {
- handleBack.remove();
- handleBack = null;
- title = null;
- content = null;
- timer = null;
- timestamp = null;
- };
- }, []);
-
- useEffect(() => {
- SideMenuEvent.close();
- SideMenuEvent.disable();
- return () => {
- DDS.isTab ? SideMenuEvent.open() : null;
- SideMenuEvent.enable();
- };
- });
-
- useEffect(() => {
- EditorWebView.reload();
- }, [colors]);
-
- return DDS.isTab ? (
- <View
- style={{
- flexDirection: 'row',
- width: '100%',
- }}>
- <AnimatedSafeAreaView
- transition={['backgroundColor', 'width']}
+ {_renderEditor()}
+ </AnimatedSafeAreaView>
+ <Animatable.View
+ transition={['width', 'opacity']}
+ duration={300}
+ style={{
+ width: sidebar ? '30%' : '0%',
+ opacity: sidebar ? 1 : 0,
+ }}>
+ <EditorMenu
+ hide={false}
+ noteProps={noteProps}
+ updateProps={props => {
+ setNoteProps(props);
+ }}
+ close={() => {
+ setTimeout(() => {
+ setOpen(args);
+ }, 500);
+ }}
+ />
+ </Animatable.View>
+ </View>
+ ) : (
+ <Animatable.View
+ transition="backgroundColor"
duration={300}
style={{
- height: '100%',
backgroundColor: colors.bg,
- width: sidebar ? '70%' : '100%',
+ flex: 1,
}}>
- <Dialog
- title="Close Editor"
- visible={dialog}
- icon="x"
- paragraph="Are you sure you want to close editor?"
- close={() => {
- setDialog(false);
- }}
- positivePress={() => {
- setTimeout(() => {
+ <AnimatedSafeAreaView
+ transition="backgroundColor"
+ duration={300}
+ style={{height: '100%', backgroundColor: colors.bg}}>
+ <Dialog
+ title="Close Editor"
+ visible={dialog}
+ icon="x"
+ paragraph="Are you sure you want to close editor?"
+ close={() => {
+ setDialog(false);
+ }}
+ positivePress={() => {
navigation.goBack();
setDialog(false);
- }, 1000);
+ }}
+ />
+
+ {_renderEditor()}
+ </AnimatedSafeAreaView>
+
+ <Dialog
+ visible={visible}
+ title="Delete note"
+ icon="trash"
+ paragraph="Do you want to delete this note?"
+ positiveText="Delete"
+ positivePress={deleteItem}
+ close={() => {
+ setVisible(false);
}}
/>
- {_renderEditor()}
- </AnimatedSafeAreaView>
- <Animatable.View
- transition={['width', 'opacity']}
- duration={300}
- style={{
- width: sidebar ? '30%' : '0%',
- opacity: sidebar ? 1 : 0,
- }}>
- <EditorMenu
- hide={false}
- noteProps={noteProps}
- updateProps={props => {
+ <VaultDialog
+ close={(item, locked) => {
+ let props = {...noteProps};
+ props.locked = locked;
+ note.locked = locked;
setNoteProps(props);
+ setVaultDialog(false);
+ setUnlock(false);
}}
- close={() => {
- setTimeout(() => {
- setOpen(args);
- }, 500);
- }}
+ note={note}
+ timestamp={timestamp}
+ perm={true}
+ openedToUnlock={unlock}
+ visible={vaultDialog}
/>
- </Animatable.View>
- </View>
- ) : (
- <Animatable.View
- transition="backgroundColor"
- duration={300}
- style={{
- backgroundColor: colors.bg,
- flex: 1,
- }}>
- <AnimatedSafeAreaView
- transition="backgroundColor"
- duration={300}
- style={{height: '100%', backgroundColor: colors.bg}}>
- <Dialog
- title="Close Editor"
- visible={dialog}
- icon="x"
- paragraph="Are you sure you want to close editor?"
- close={() => {
- setDialog(false);
- }}
- positivePress={() => {
- navigation.goBack();
- setDialog(false);
+ <ActionSheet
+ ref={ref => (actionSheet = ref)}
+ customStyles={{
+ backgroundColor: colors.bg,
}}
- />
-
- {_renderEditor()}
- </AnimatedSafeAreaView>
-
- <Dialog
- visible={visible}
- title="Delete note"
- icon="trash"
- paragraph="Do you want to delete this note?"
- positiveText="Delete"
- positivePress={deleteItem}
- close={() => {
- setVisible(false);
- }}
- />
-
- <VaultDialog
- close={(item, locked) => {
- let props = {...noteProps};
- props.locked = locked;
- note.locked = locked;
- setNoteProps(props);
- setVaultDialog(false);
- setUnlock(false);
- }}
- note={note}
- timestamp={timestamp}
- perm={true}
- openedToUnlock={unlock}
- visible={vaultDialog}
- />
- <ActionSheet
- ref={ref => (actionSheet = ref)}
- customStyles={{
- backgroundColor: colors.bg,
- }}
- initialOffsetFromBottom={0.99}
- elevation={5}
- overlayColor={
- colors.night ? 'rgba(225,225,225,0.1)' : 'rgba(0,0,0,0.3)'
- }
- indicatorColor={colors.shade}
- onClose={() => {
- onMenuHide();
- if (willRefresh) {
- note = db.getNote(timestamp);
-
- updateEditor();
+ initialOffsetFromBottom={0.99}
+ elevation={5}
+ overlayColor={
+ colors.night ? 'rgba(225,225,225,0.1)' : 'rgba(0,0,0,0.3)'
}
- }}
- children={
- <ActionSheetComponent
- item={note}
- setWillRefresh={value => {
- cutsomNote = value;
- willRefresh = true;
- }}
- hasColors={true}
- hasTags={true}
- rowItems={['Add to', 'Share', 'Export', 'Delete']}
- columnItems={['Dark Mode', 'Add to Vault', 'Pin', 'Favorite']}
- close={value => {
- if (value) {
- show = value;
- }
+ indicatorColor={colors.shade}
+ onClose={() => {
+ onMenuHide();
+ if (willRefresh) {
+ note = db.getNote(timestamp);
- actionSheet._setModalVisible();
- }}
- />
- }
- />
- </Animatable.View>
- );
+ updateEditor();
+ }
+ }}
+ children={
+ <ActionSheetComponent
+ item={note}
+ setWillRefresh={value => {
+ cutsomNote = value;
+ willRefresh = true;
+ }}
+ hasColors={true}
+ hasTags={true}
+ rowItems={['Add to', 'Share', 'Export', 'Delete']}
+ columnItems={['Dark Mode', 'Add to Vault', 'Pin', 'Favorite']}
+ close={value => {
+ if (value) {
+ show = value;
+ }
+
+ actionSheet._setModalVisible();
+ }}
+ />
+ }
+ />
+ </Animatable.View>
+ );
+ }
};
Editor.navigationOptions = {
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index 16b6d3421..f2e84a6a5 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -27,162 +27,168 @@ export const Favorites = ({navigation}) => {
const [buttonHide, setButtonHide] = useState(false);
// Variables
+ let isFocused = useIsFocused();
- let offsetY = 0;
- let countUp = 1;
- let countDown = 0;
+ if (!isFocused) {
+ console.log('block rerender');
+ return <></>;
+ } else {
+ let offsetY = 0;
+ let countUp = 1;
+ let countDown = 0;
- // Functions
+ // Functions
- // Effects
- const onScroll = event => {
- let y = event.nativeEvent.contentOffset.y;
- if (buttonHide) return;
- if (y < 30) setHideHeader(false);
- if (y > offsetY) {
- if (y - offsetY < 150 || countDown > 0) return;
- countDown = 1;
- countUp = 0;
- setHideHeader(true);
- } else {
- if (offsetY - y < 150 || countUp > 0) return;
- countDown = 0;
- countUp = 1;
- setHideHeader(false);
- }
- offsetY = y;
- };
- // Render
+ // Effects
+ const onScroll = event => {
+ let y = event.nativeEvent.contentOffset.y;
+ if (buttonHide) return;
+ if (y < 30) setHideHeader(false);
+ if (y > offsetY) {
+ if (y - offsetY < 150 || countDown > 0) return;
+ countDown = 1;
+ countUp = 0;
+ setHideHeader(true);
+ } else {
+ if (offsetY - y < 150 || countUp > 0) return;
+ countDown = 0;
+ countUp = 1;
+ setHideHeader(false);
+ }
+ offsetY = y;
+ };
+ // Render
- return (
- <Container noBottomButton={true}>
- <Animatable.View
- transition="backgroundColor"
- duration={300}
- style={{
- position: 'absolute',
- backgroundColor: colors.night ? colors.bg : colors.bg,
- zIndex: 10,
- width: '100%',
- }}>
- <Header
- menu={true}
- hide={hideHeader}
- showSearch={() => {
- setHideHeader(false);
- countUp = 0;
- countDown = 0;
- }}
- colors={colors}
- heading="Favorites"
- canGoBack={false}
- customIcon="menu"
- />
- {favorites.length > 0 ? (
- <Search
- clear={() => setText('')}
+ return (
+ <Container noBottomButton={true}>
+ <Animatable.View
+ transition="backgroundColor"
+ duration={300}
+ style={{
+ position: 'absolute',
+ backgroundColor: colors.night ? colors.bg : colors.bg,
+ zIndex: 10,
+ width: '100%',
+ }}>
+ <Header
+ menu={true}
hide={hideHeader}
- placeholder="Search your notes"
- value={text}
+ showSearch={() => {
+ setHideHeader(false);
+ countUp = 0;
+ countDown = 0;
+ }}
+ colors={colors}
+ heading="Favorites"
+ canGoBack={false}
+ customIcon="menu"
/>
- ) : null}
- </Animatable.View>
+ {favorites.length > 0 ? (
+ <Search
+ clear={() => setText('')}
+ hide={hideHeader}
+ placeholder="Search your notes"
+ value={text}
+ />
+ ) : null}
+ </Animatable.View>
- <FlatList
- //keyExtractor={item => item.dateCreated.toString()}
- style={{
- width: '100%',
- alignSelf: 'center',
- height: '100%',
- }}
- contentContainerStyle={{
- height: '100%',
- }}
- ListHeaderComponent={
- <View
- style={{
- marginTop:
- Platform.OS == 'ios'
- ? favorites[0]
- ? 135
- : 135 - 60
- : favorites[0]
- ? 155
- : 155 - 60,
- }}></View>
- }
- ListEmptyComponent={
- <View
- style={{
- height: '80%',
- width: '100%',
- alignItems: 'center',
- alignSelf: 'center',
- justifyContent: 'center',
- opacity: 0.8,
- }}>
- <FavoritesPlaceHolder />
- <Text
+ <FlatList
+ //keyExtractor={item => item.dateCreated.toString()}
+ style={{
+ width: '100%',
+ alignSelf: 'center',
+ height: '100%',
+ }}
+ contentContainerStyle={{
+ height: '100%',
+ }}
+ ListHeaderComponent={
+ <View
style={{
- color: colors.pri,
- fontSize: SIZE.md,
- fontFamily: WEIGHT.regular,
- marginTop: 20,
- }}>
- Favorite notes & notebooks appear here.
- </Text>
- <Text
+ marginTop:
+ Platform.OS == 'ios'
+ ? favorites[0]
+ ? 135
+ : 135 - 60
+ : favorites[0]
+ ? 155
+ : 155 - 60,
+ }}></View>
+ }
+ ListEmptyComponent={
+ <View
style={{
- fontSize: SIZE.sm,
- color: colors.icon,
- marginTop: 20,
+ height: '80%',
+ width: '100%',
+ alignItems: 'center',
+ alignSelf: 'center',
+ justifyContent: 'center',
+ opacity: 0.8,
}}>
- Favorites are empty.
- </Text>
- </View>
- }
- data={favorites}
- onScroll={onScroll}
- renderItem={({item, index}) => (
- <SelectionWrapper item={item}>
- {item.type === 'note' ? (
- <NoteItem
- customStyle={{
- width: selectionMode ? w - 74 : '100%',
- marginHorizontal: 0,
- }}
- onLongPress={() => {
- if (!selectionMode) {
- updateSelectionList(item);
- }
- changeSelectionMode(!selectionMode);
- }}
- item={item}
- index={index}
- isTrash={true}
- />
- ) : (
- <NotebookItem
- onLongPress={() => {
- if (!selectionMode) {
- updateSelectionList(item);
- }
- changeSelectionMode(!selectionMode);
- }}
- customStyle={{
- width: selectionMode ? w - 74 : '100%',
- marginHorizontal: 0,
- }}
- item={item}
- isTrash={true}
- index={index}
- />
- )}
- </SelectionWrapper>
- )}
- />
- </Container>
- );
+ <FavoritesPlaceHolder />
+ <Text
+ style={{
+ color: colors.pri,
+ fontSize: SIZE.md,
+ fontFamily: WEIGHT.regular,
+ marginTop: 20,
+ }}>
+ Favorite notes & notebooks appear here.
+ </Text>
+ <Text
+ style={{
+ fontSize: SIZE.sm,
+ color: colors.icon,
+ marginTop: 20,
+ }}>
+ Favorites are empty.
+ </Text>
+ </View>
+ }
+ data={favorites}
+ onScroll={onScroll}
+ renderItem={({item, index}) => (
+ <SelectionWrapper item={item}>
+ {item.type === 'note' ? (
+ <NoteItem
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
+ changeSelectionMode(!selectionMode);
+ }}
+ item={item}
+ index={index}
+ isTrash={true}
+ />
+ ) : (
+ <NotebookItem
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
+ changeSelectionMode(!selectionMode);
+ }}
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
+ item={item}
+ isTrash={true}
+ index={index}
+ />
+ )}
+ </SelectionWrapper>
+ )}
+ />
+ </Container>
+ );
+ }
};
Favorites.navigationOptions = {
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index 9a1104c32..3e291edc6 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -27,207 +27,214 @@ export const Folders = ({navigation}) => {
const [addNotebook, setAddNotebook] = useState(false);
const [hideHeader, setHideHeader] = useState(false);
- const params = navigation.state.params;
- let offsetY = 0;
- let countUp = 0;
- let countDown = 0;
+ let isFocused = useIsFocused();
- const onScroll = event => {
- y = event.nativeEvent.contentOffset.y;
- if (y < 30) setHideHeader(false);
- //if (buttonHide) return;
- if (y > offsetY) {
- if (y - offsetY < 150 || countDown > 0) return;
- countDown = 1;
- countUp = 0;
- setHideHeader(true);
- } else {
- if (offsetY - y < 150 || countUp > 0) return;
- countDown = 0;
- countUp = 1;
- setHideHeader(false);
- }
- offsetY = y;
- };
+ if (!isFocused) {
+ console.log('block rerender');
+ return <></>;
+ } else {
+ const params = navigation.state.params;
+ let offsetY = 0;
+ let countUp = 0;
+ let countDown = 0;
- return (
- <Container
- bottomButtonText="Add a new notebook"
- bottomButtonOnPress={() => {
- setAddNotebook(true);
- }}>
- <AddNotebookDialog
- visible={addNotebook}
- close={newNotes => {
- setAddNotebook(false);
- if (newNotes) {
- updateDB();
- }
- }}
- />
-
- <SelectionHeader />
-
- <Animatable.View
- transition={['backgroundColor', 'opacity', 'height']}
- duration={300}
- style={{
- position: 'absolute',
- backgroundColor: colors.bg,
- height: selectionMode ? 0 : null,
- opacity: selectionMode ? 0 : 1,
- zIndex: 10,
- width: '100%',
+ const onScroll = event => {
+ y = event.nativeEvent.contentOffset.y;
+ if (y < 30) setHideHeader(false);
+ //if (buttonHide) return;
+ if (y > offsetY) {
+ if (y - offsetY < 150 || countDown > 0) return;
+ countDown = 1;
+ countUp = 0;
+ setHideHeader(true);
+ } else {
+ if (offsetY - y < 150 || countUp > 0) return;
+ countDown = 0;
+ countUp = 1;
+ setHideHeader(false);
+ }
+ offsetY = y;
+ };
+ console.log('rerendering folders');
+ return (
+ <Container
+ bottomButtonText="Add a new notebook"
+ bottomButtonOnPress={() => {
+ setAddNotebook(true);
}}>
- <Header
- hide={hideHeader}
- menu={params.canGoBack ? false : true}
- showSearch={() => {
- setHideHeader(false);
- countUp = 0;
- countDown = 0;
+ <AddNotebookDialog
+ visible={addNotebook}
+ close={newNotes => {
+ setAddNotebook(false);
+ if (newNotes) {
+ updateDB();
+ }
}}
- colors={colors}
- heading={params.title}
- canGoBack={params.canGoBack}
/>
- {notebooks.length == 0 ? null : (
- <Search placeholder="Search your notebook" hide={hideHeader} />
- )}
- </Animatable.View>
- <FlatList
- style={{
- width: '100%',
- }}
- onScroll={onScroll}
- ListHeaderComponent={
- <View
- style={{
- marginTop:
- Platform.OS == 'ios'
- ? notebooks[0] && !selectionMode
- ? 135
- : 135 - 60
- : notebooks[0] && !selectionMode
- ? 155
- : 155 - 60,
- }}>
- {pinned && pinned.length > 0 ? (
- <>
- <FlatList
- data={pinned}
- keyExtractor={(item, index) => item.dateCreated.toString()}
- renderItem={({item, index}) =>
- item.type === 'notebook' ? (
- <SelectionWrapper item={item}>
- <NotebookItem
- hideMore={params.hideMore}
- customStyle={{
- width: selectionMode ? w - 74 : '100%',
- marginHorizontal: 0,
- }}
- isMove={params.isMove}
- onLongPress={() => {
- changeSelectionMode();
- }}
- noteToMove={params.note}
- item={item}
- pinned={true}
- index={index}
- colors={colors}
- />
- </SelectionWrapper>
- ) : null
- }
- />
- </>
- ) : null}
- </View>
- }
- ListEmptyComponent={
- pinned && pinned.length > 0 ? null : (
+ <SelectionHeader />
+
+ <Animatable.View
+ transition={['backgroundColor', 'opacity', 'height']}
+ duration={300}
+ style={{
+ position: 'absolute',
+ backgroundColor: colors.bg,
+ height: selectionMode ? 0 : null,
+ opacity: selectionMode ? 0 : 1,
+ zIndex: 10,
+ width: '100%',
+ }}>
+ <Header
+ hide={hideHeader}
+ menu={params.canGoBack ? false : true}
+ showSearch={() => {
+ setHideHeader(false);
+ countUp = 0;
+ countDown = 0;
+ }}
+ colors={colors}
+ heading={params.title}
+ canGoBack={params.canGoBack}
+ />
+ {notebooks.length == 0 ? null : (
+ <Search placeholder="Search your notebook" hide={hideHeader} />
+ )}
+ </Animatable.View>
+
+ <FlatList
+ style={{
+ width: '100%',
+ }}
+ onScroll={onScroll}
+ ListHeaderComponent={
<View
style={{
- height: '80%',
- width: '100%',
- alignItems: 'center',
- alignSelf: 'center',
- justifyContent: 'center',
- opacity: 0.8,
+ marginTop:
+ Platform.OS == 'ios'
+ ? notebooks[0] && !selectionMode
+ ? 135
+ : 135 - 60
+ : notebooks[0] && !selectionMode
+ ? 155
+ : 155 - 60,
}}>
- <NotebookPlaceHolder animation={slideRight} colors={colors} />
- <NotebookPlaceHolder animation={slideLeft} colors={colors} />
- <NotebookPlaceHolder animation={slideRight} colors={colors} />
-
- <Text
+ {pinned && pinned.length > 0 ? (
+ <>
+ <FlatList
+ data={pinned}
+ keyExtractor={(item, index) => item.dateCreated.toString()}
+ renderItem={({item, index}) =>
+ item.type === 'notebook' ? (
+ <SelectionWrapper item={item}>
+ <NotebookItem
+ hideMore={params.hideMore}
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
+ isMove={params.isMove}
+ onLongPress={() => {
+ changeSelectionMode();
+ }}
+ noteToMove={params.note}
+ item={item}
+ pinned={true}
+ index={index}
+ colors={colors}
+ />
+ </SelectionWrapper>
+ ) : null
+ }
+ />
+ </>
+ ) : null}
+ </View>
+ }
+ ListEmptyComponent={
+ pinned && pinned.length > 0 ? null : (
+ <View
style={{
- color: colors.icon,
- fontSize: SIZE.md,
- fontFamily: WEIGHT.regular,
- marginTop: 20,
+ height: '80%',
+ width: '100%',
+ alignItems: 'center',
+ alignSelf: 'center',
+ justifyContent: 'center',
+ opacity: 0.8,
}}>
- Notebooks you add will appear here
- </Text>
+ <NotebookPlaceHolder animation={slideRight} colors={colors} />
+ <NotebookPlaceHolder animation={slideLeft} colors={colors} />
+ <NotebookPlaceHolder animation={slideRight} colors={colors} />
+
+ <Text
+ style={{
+ color: colors.icon,
+ fontSize: SIZE.md,
+ fontFamily: WEIGHT.regular,
+ marginTop: 20,
+ }}>
+ Notebooks you add will appear here
+ </Text>
+ <Text
+ style={{
+ fontSize: SIZE.sm,
+ color: colors.icon,
+ marginTop: 20,
+ }}>
+ No Notebooks found
+ </Text>
+ </View>
+ )
+ }
+ contentContainerStyle={{
+ width: '100%',
+ alignSelf: 'center',
+ }}
+ ListFooterComponent={
+ <View
+ style={{
+ height: 150,
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}>
<Text
style={{
+ color: colors.navbg,
fontSize: SIZE.sm,
- color: colors.icon,
- marginTop: 20,
+ fontFamily: WEIGHT.regular,
}}>
- No Notebooks found
+ - End -
</Text>
</View>
- )
- }
- contentContainerStyle={{
- width: '100%',
- alignSelf: 'center',
- }}
- ListFooterComponent={
- <View
- style={{
- height: 150,
- alignItems: 'center',
- justifyContent: 'center',
- }}>
- <Text
- style={{
- color: colors.navbg,
- fontSize: SIZE.sm,
- fontFamily: WEIGHT.regular,
- }}>
- - End -
- </Text>
- </View>
- }
- data={notebooks}
- keyExtractor={(item, index) => item.dateCreated.toString()}
- renderItem={({item, index}) => (
- <SelectionWrapper item={item}>
- <NotebookItem
- hideMore={params.hideMore}
- customStyle={{
- width: selectionMode ? w - 74 : '100%',
- marginHorizontal: 0,
- }}
- isMove={params.isMove}
- onLongPress={() => {
- if (!selectionMode) {
- updateSelectionList(item);
- }
+ }
+ data={notebooks}
+ keyExtractor={(item, index) => item.dateCreated.toString()}
+ renderItem={({item, index}) => (
+ <SelectionWrapper item={item}>
+ <NotebookItem
+ hideMore={params.hideMore}
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
+ isMove={params.isMove}
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
- changeSelectionMode(!selectionMode);
- }}
- noteToMove={params.note}
- item={item}
- index={index}
- />
- </SelectionWrapper>
- )}
- />
- </Container>
- );
+ changeSelectionMode(!selectionMode);
+ }}
+ noteToMove={params.note}
+ item={item}
+ index={index}
+ />
+ </SelectionWrapper>
+ )}
+ />
+ </Container>
+ );
+ }
};
Folders.navigationOptions = {
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index c249bcb9e..6e4eee97b 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -11,6 +11,7 @@ import {useAppContext} from '../../provider/useAppContext';
import {DDS} from '../../../App';
import Container from '../../components/Container';
import SelectionHeader from '../../components/SelectionHeader';
+import {useIsFocused} from 'react-navigation-hooks';
export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(
SafeAreaView,
);
@@ -23,130 +24,143 @@ export const Home = ({navigation}) => {
const [keyword, setKeyword] = useState('');
const [searchResults, setSearchResults] = useState([]);
// Variables
- let offsetY = 0;
- let countUp = 1;
- let countDown = 0;
- let searchResult = null;
-
- // Effects
-
- useEffect(() => {
- DDS.isTab ? setMenuOpen() : null;
- }, []);
-
- // Functions
-
- const onChangeText = value => {
- setText(value);
- };
- const onSubmitEditing = async () => {
- if (!text || text.length < 1) {
- clearSearch();
- } else {
- setKeyword(text);
- searchResult = await db.searchNotes(text);
-
- if (searchResult && searchResult.length > 0) {
- setSearchResults([...searchResult]);
+ let isFocused = useIsFocused();
+
+ if (!isFocused) {
+ console.log('block rerender');
+ return <></>;
+ } else {
+ let offsetY = 0;
+ let countUp = 1;
+ let countDown = 0;
+ let searchResult = null;
+
+ // Effects
+
+ useEffect(() => {
+ DDS.isTab ? setMenuOpen() : null;
+ }, []);
+
+ // Functions
+
+ const onChangeText = value => {
+ setText(value);
+ };
+ const onSubmitEditing = async () => {
+ if (!text || text.length < 1) {
+ clearSearch();
} else {
- ToastEvent.show('No search results found', 'error', 3000, () => {}, '');
+ setKeyword(text);
+ searchResult = await db.searchNotes(text);
+
+ if (searchResult && searchResult.length > 0) {
+ setSearchResults([...searchResult]);
+ } else {
+ ToastEvent.show(
+ 'No search results found',
+ 'error',
+ 3000,
+ () => {},
+ '',
+ );
+ }
}
- }
- };
-
- const onBlur = () => {
- if (text && text.length < 1) {
- clearSearch();
- }
- };
-
- const onFocus = () => {
- //setSearch(false);
- };
-
- const clearSearch = () => {
- searchResult = null;
- setSearchResults([...[]]);
- };
-
- const onScroll = y => {
- if (searchResults.length > 0) return;
- if (y < 30) setHideHeader(false);
- if (y > offsetY) {
- if (y - offsetY < 150 || countDown > 0) return;
- countDown = 1;
- countUp = 0;
- setHideHeader(true);
- } else {
- if (offsetY - y < 150 || countUp > 0) return;
- countDown = 0;
- countUp = 1;
- setHideHeader(false);
- }
- offsetY = y;
- };
-
- // Render
-
- return (
- <Container
- bottomButtonText="Add a new note"
- bottomButtonOnPress={() => {
- SideMenuEvent.close();
- SideMenuEvent.disable();
- NavigationService.navigate('Editor');
- }}>
- <SelectionHeader />
- <Animatable.View
- transition={['backgroundColor', 'opacity', 'height']}
- duration={300}
- style={{
- position: 'absolute',
- backgroundColor: colors.bg,
- zIndex: 10,
- height: selectionMode ? 0 : null,
- opacity: selectionMode ? 0 : 1,
- width: '100%',
- }}>
- <Header
- menu
- hide={hideHeader}
- verticalMenu
- showSearch={() => {
- setHideHeader(false);
- countUp = 0;
- countDown = 0;
- }}
- colors={colors}
- heading="Home"
- canGoBack={false}
- customIcon="menu"
- />
+ };
- {notes[0] ? (
- <Search
- clear={() => setText('')}
+ const onBlur = () => {
+ if (text && text.length < 1) {
+ clearSearch();
+ }
+ };
+
+ const onFocus = () => {
+ //setSearch(false);
+ };
+
+ const clearSearch = () => {
+ searchResult = null;
+ setSearchResults([...[]]);
+ };
+
+ const onScroll = y => {
+ if (searchResults.length > 0) return;
+ if (y < 30) setHideHeader(false);
+ if (y > offsetY) {
+ if (y - offsetY < 150 || countDown > 0) return;
+ countDown = 1;
+ countUp = 0;
+ setHideHeader(true);
+ } else {
+ if (offsetY - y < 150 || countUp > 0) return;
+ countDown = 0;
+ countUp = 1;
+ setHideHeader(false);
+ }
+ offsetY = y;
+ };
+
+ // Render
+ console.log('rerendering home');
+ return (
+ <Container
+ bottomButtonText="Add a new note"
+ bottomButtonOnPress={() => {
+ SideMenuEvent.close();
+ SideMenuEvent.disable();
+ NavigationService.navigate('Editor');
+ }}>
+ <SelectionHeader />
+ <Animatable.View
+ transition={['backgroundColor', 'opacity', 'height']}
+ duration={300}
+ style={{
+ position: 'absolute',
+ backgroundColor: colors.bg,
+ zIndex: 10,
+ height: selectionMode ? 0 : null,
+ opacity: selectionMode ? 0 : 1,
+ width: '100%',
+ }}>
+ <Header
+ menu
hide={hideHeader}
- onChangeText={onChangeText}
- onSubmitEditing={onSubmitEditing}
- placeholder="Search your notes"
- onBlur={onBlur}
- onFocus={onFocus}
- clearSearch={clearSearch}
- value={text}
+ verticalMenu
+ showSearch={() => {
+ setHideHeader(false);
+ countUp = 0;
+ countDown = 0;
+ }}
+ colors={colors}
+ heading="Home"
+ canGoBack={false}
+ customIcon="menu"
/>
- ) : null}
- </Animatable.View>
-
- <NotesList
- isGrouped={true}
- onScroll={onScroll}
- isSearch={searchResults.length > 0 ? true : false}
- notes={searchResults.length > 0 ? searchResults : notes}
- keyword={keyword}
- />
- </Container>
- );
+
+ {notes[0] ? (
+ <Search
+ clear={() => setText('')}
+ hide={hideHeader}
+ onChangeText={onChangeText}
+ onSubmitEditing={onSubmitEditing}
+ placeholder="Search your notes"
+ onBlur={onBlur}
+ onFocus={onFocus}
+ clearSearch={clearSearch}
+ value={text}
+ />
+ ) : null}
+ </Animatable.View>
+
+ <NotesList
+ isGrouped={true}
+ onScroll={onScroll}
+ isSearch={searchResults.length > 0 ? true : false}
+ notes={searchResults.length > 0 ? searchResults : notes}
+ keyword={keyword}
+ />
+ </Container>
+ );
+ }
};
Home.navigationOptions = {
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index ef856018c..b89e0b999 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -1,59 +1,45 @@
import React, {useState} from 'react';
-import {
- View,
- Text,
- TouchableOpacity,
- Platform,
- FlatList,
- KeyboardAvoidingView,
-} from 'react-native';
-import {SIZE, ph, pv, opacity, WEIGHT} from '../../common/common';
-import Icon from 'react-native-vector-icons/Feather';
+import {View, Text, Platform} from 'react-native';
+import {SIZE, WEIGHT} from '../../common/common';
import {Header} from '../../components/header';
import {NotebookItem} from '../../components/NotebookItem';
import {Search} from '../../components/SearchInput';
-import {useForceUpdate} from '../ListsEditor';
import {AddTopicDialog} from '../../components/AddTopicDialog';
-import {AnimatedSafeAreaView} from '../Home';
import * as Animatable from 'react-native-animatable';
-import {NavigationEvents} from 'react-navigation';
import {useAppContext} from '../../provider/useAppContext';
+import {useIsFocused} from 'react-navigation-hooks';
+import Container from '../../components/Container';
export const Notebook = ({navigation}) => {
- // State
const {colors} = useAppContext();
const params = navigation.state.params;
const [hideHeader, setHideHeader] = useState(false);
const [buttonHide, setButtonHide] = useState(false);
- const [numColumns, setNumColumns] = useState(1);
const [addTopic, setAddTopic] = useState(false);
- const forceUpdate = useForceUpdate();
- // Variables
- let offsetY = 0;
- let countUp = 0;
- let countDown = 0;
- // Effects
+ let isFocused = useIsFocused();
- // Functions
+ if (!isFocused) {
+ console.log('block rerender');
+ return <></>;
+ } else {
+ // State
- // Render
- return (
- <AnimatedSafeAreaView
- transition="backgroundColor"
- duration={300}
- style={{
- height: '100%',
- backgroundColor: colors.bg,
- }}>
- <NavigationEvents
- onDidBlur={() => {
- marginSet = false;
- }}
- />
- <KeyboardAvoidingView
- style={{
- height: '100%',
+ // Variables
+ let offsetY = 0;
+ let countUp = 0;
+ let countDown = 0;
+
+ // Effects
+
+ // Functions
+
+ // Render
+ return (
+ <Container
+ bottomButtonText="Add new topic"
+ bottomButtonOnPress={() => {
+ setAddTopic(true);
}}>
<AddTopicDialog
visible={addTopic}
@@ -111,16 +97,17 @@ export const Notebook = ({navigation}) => {
ListHeaderComponent={
<View
style={{
- marginTop: Platform.OS == 'ios' ? 145 : 185,
- }}></View>
+ marginTop:
+ Platform.OS == 'ios'
+ ? notebooks[0] && !selectionMode
+ ? 135
+ : 135 - 60
+ : notebooks[0] && !selectionMode
+ ? 155
+ : 155 - 60,
+ }}
+ />
}
- numColumns={numColumns}
- key={numColumns}
- contentContainerStyle={{
- width: '100%',
- alignItems: numColumns === 2 ? 'flex-start' : null,
- alignSelf: 'center',
- }}
ListFooterComponent={
<View
style={{
@@ -146,7 +133,7 @@ export const Notebook = ({navigation}) => {
notebookID={params.notebook.dateCreated}
isMove={params.isMove}
refresh={() => {
- forceUpdate();
+ //forceUpdate();
}}
item={item}
index={index}
@@ -154,36 +141,9 @@ export const Notebook = ({navigation}) => {
/>
)}
/>
- <TouchableOpacity
- activeOpacity={opacity}
- onPress={() => {
- setAddTopic(true);
- }}
- style={{
- borderRadius: 5,
- width: w - 24,
- marginHorizontal: 12,
- paddingHorizontal: ph,
- paddingVertical: pv + 5,
- flexDirection: 'row',
- justifyContent: 'flex-start',
- alignItems: 'center',
- marginBottom: 15,
- backgroundColor: colors.accent,
- }}>
- <Icon name="plus" color="white" size={SIZE.lg} />
- <Text
- style={{
- fontSize: SIZE.md,
- fontFamily: WEIGHT.regular,
- color: 'white',
- }}>
- {' '}Add a new topic
- </Text>
- </TouchableOpacity>
- </KeyboardAvoidingView>
- </AnimatedSafeAreaView>
- );
+ </Container>
+ );
+ }
};
Notebook.navigationOptions = {
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index e129c83a0..c6175ffb7 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -24,6 +24,7 @@ import {db} from '../../../App';
import * as Animatable from 'react-native-animatable';
import {useAppContext} from '../../provider/useAppContext';
import {w} from '../../utils/utils';
+import Container from '../../components/Container';
export const Notes = ({navigation}) => {
const {colors} = useAppContext();
@@ -32,51 +33,50 @@ export const Notes = ({navigation}) => {
const [buttonHide, setButtonHide] = useState(false);
const [notes, setNotes] = useState([]);
const forceUpdate = useForceUpdate();
- let params = navigation.state ? navigation.state.params : null;
- let offsetY = 0;
- let countUp = 0;
- let countDown = 0;
- let headerHeight = 0;
- let searchHeight = 0;
- let marginSet = false;
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
+
+ let isFocused = useIsFocused();
+
+ if (!isFocused) {
+ console.log('block rerender');
+ return <></>;
+ } else {
+ let params = navigation.state ? navigation.state.params : null;
+ let offsetY = 0;
+ let countUp = 0;
+ let countDown = 0;
+ let headerHeight = 0;
+ let searchHeight = 0;
+ let marginSet = false;
+ useEffect(() => {
+ onThemeUpdate(() => {
forceUpdate();
});
- };
- }, []);
-
- useEffect(() => {
- if (!params) {
- params = {
- heading: 'Notes',
+ return () => {
+ clearThemeUpdateListener(() => {
+ forceUpdate();
+ });
};
- }
- }, []);
+ }, []);
+
+ useEffect(() => {
+ if (!params) {
+ params = {
+ heading: 'Notes',
+ };
+ }
+ }, []);
- useEffect(() => {
- let allNotes = db.getTopic(params.notebookID, params.title);
- if (allNotes && allNotes.length > 0) {
- setNotes(allNotes);
- }
- }, []);
+ useEffect(() => {
+ let allNotes = db.getTopic(params.notebookID, params.title);
+ if (allNotes && allNotes.length > 0) {
+ setNotes(allNotes);
+ }
+ }, []);
- return (
- <AnimatedSafeAreaView
- transition="backgroundColor"
- duration={300}
- style={{
- height: '100%',
- backgroundColor: colors.bg,
- }}>
- <KeyboardAvoidingView
- style={{
- height: '100%',
- }}>
+ return (
+ <Container
+ bottomButtonText="Create a new note"
+ bottomButtonOnPress={() => {}}>
<Animatable.View
transition="backgroundColor"
duration={300}
@@ -131,37 +131,9 @@ export const Notes = ({navigation}) => {
notes={notes}
keyword={null}
/>
-
- <TouchableOpacity
- activeOpacity={opacity}
- onPress={() => {
- setAddNotebook(true);
- }}
- style={{
- borderRadius: 5,
- width: w - 24,
- marginHorizontal: 12,
- paddingHorizontal: ph,
- paddingVertical: pv + 5,
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'center',
- marginBottom: 15,
- backgroundColor: colors.accent,
- }}>
- <Text
- style={{
- fontSize: SIZE.md,
- fontFamily: WEIGHT.semibold,
- color: 'white',
- }}>
- <Icon name="plus" color="white" size={SIZE.lg} />
- {' '} Create a new note
- </Text>
- </TouchableOpacity>
- </KeyboardAvoidingView>
- </AnimatedSafeAreaView>
- );
+ </Container>
+ );
+ }
};
Notes.navigationOptions = {
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 38f884d57..c63711058 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useState} from 'react';
import {
ScrollView,
View,
@@ -21,17 +21,20 @@ import {FlatList} from 'react-native-gesture-handler';
import AsyncStorage from '@react-native-community/async-storage';
import {AnimatedSafeAreaView} from '../Home';
import {useAppContext} from '../../provider/useAppContext';
+import {useIsFocused} from 'react-navigation-hooks';
+import Container from '../../components/Container';
export const Settings = ({navigation}) => {
const {colors, changeAccentColor, changeColorScheme} = useAppContext();
+ //const [colors, setColors] = useState(COLOR_SCHEME_LIGHT);
+ let isFocused = useIsFocused();
+
+ if (!isFocused) {
+ console.log('block rerender');
+ return <></>;
+ }
return (
- <AnimatedSafeAreaView
- transition="backgroundColor"
- duration={300}
- style={{
- backgroundColor: colors.bg,
- height: '100%',
- }}>
+ <Container noBottomButton={true}>
<View>
<Header
menu={true}
@@ -189,7 +192,7 @@ export const Settings = ({navigation}) => {
)}
/>
</View>
- </AnimatedSafeAreaView>
+ </Container>
);
};
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index 698d6d267..e075abd1f 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -10,92 +10,98 @@ const h = Dimensions.get('window').height;
export const Tags = ({navigation}) => {
const {colors} = useAppContext();
+ let isFocused = useIsFocused();
- return (
- <SafeAreaView
- style={{
- height: '100%',
- backgroundColor: colors.bg,
- }}>
- <Header canGoBack={false} heading="Tags" menu={true} />
+ if (!isFocused) {
+ console.log('block rerender');
+ return <></>;
+ } else {
+ return (
+ <SafeAreaView
+ style={{
+ height: '100%',
+ backgroundColor: colors.bg,
+ }}>
+ <Header canGoBack={false} heading="Tags" menu={true} />
- <View style={{width: '90%', alignSelf: 'center', height: '100%'}}>
- <FlatList
- style={{
- height: '100%',
- }}
- contentContainerStyle={{
- height: '100%',
- }}
- data={[]}
- ListEmptyComponent={
- <View
- style={{
- height: '80%',
- width: '100%',
- alignItems: 'center',
- alignSelf: 'center',
- justifyContent: 'center',
- opacity: 0.8,
- }}>
- <TagsPlaceHolder colors={colors} />
- <Text
+ <View style={{width: '90%', alignSelf: 'center', height: '100%'}}>
+ <FlatList
+ style={{
+ height: '100%',
+ }}
+ contentContainerStyle={{
+ height: '100%',
+ }}
+ data={[]}
+ ListEmptyComponent={
+ <View
style={{
- fontSize: SIZE.md,
- color: colors.icon,
- }}>
- Tags added to notes appear here
- </Text>
- <Text
- style={{
- fontSize: SIZE.sm,
- color: colors.icon,
- marginTop: 20,
- }}>
- No tags found
- </Text>
- </View>
- }
- renderItem={({item, index}) => (
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'flex-start',
- alignItems: 'center',
- margin: 5,
- paddingVertical: pv,
- borderBottomWidth: 1.5,
- borderBottomColor: colors.navbg,
- }}>
- <Text
- style={{
- fontFamily: WEIGHT.regular,
- fontSize: SIZE.md,
- color: colors.pri,
+ height: '80%',
+ width: '100%',
+ alignItems: 'center',
+ alignSelf: 'center',
+ justifyContent: 'center',
+ opacity: 0.8,
}}>
+ <TagsPlaceHolder colors={colors} />
<Text
style={{
- color: colors.accent,
+ fontSize: SIZE.md,
+ color: colors.icon,
}}>
- #
+ Tags added to notes appear here
</Text>
- {item.slice(1)}
-
- {'\n'}
<Text
style={{
- fontSize: SIZE.xs,
+ fontSize: SIZE.sm,
color: colors.icon,
+ marginTop: 20,
}}>
- 10 notes
+ No tags found
+ </Text>
+ </View>
+ }
+ renderItem={({item, index}) => (
+ <View
+ style={{
+ flexDirection: 'row',
+ justifyContent: 'flex-start',
+ alignItems: 'center',
+ margin: 5,
+ paddingVertical: pv,
+ borderBottomWidth: 1.5,
+ borderBottomColor: colors.navbg,
+ }}>
+ <Text
+ style={{
+ fontFamily: WEIGHT.regular,
+ fontSize: SIZE.md,
+ color: colors.pri,
+ }}>
+ <Text
+ style={{
+ color: colors.accent,
+ }}>
+ #
+ </Text>
+ {item.slice(1)}
+
+ {'\n'}
+ <Text
+ style={{
+ fontSize: SIZE.xs,
+ color: colors.icon,
+ }}>
+ 10 notes
+ </Text>
</Text>
- </Text>
- </View>
- )}
- />
- </View>
- </SafeAreaView>
- );
+ </View>
+ )}
+ />
+ </View>
+ </SafeAreaView>
+ );
+ }
};
Tags.navigationOptions = {
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 875795906..8495ea9e6 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -30,122 +30,133 @@ export const Trash = ({navigation}) => {
} = useAppContext();
const [dialog, setDialog] = useState(false);
+ let isFocused = useIsFocused();
- return (
- <Container
- bottomButtonOnPress={() => {
- setDialog(true);
- }}
- bottomButtonText="Clear all trash">
- <SelectionHeader />
- {selectionMode ? null : (
- <Header colors={colors} heading="Trash" canGoBack={false} menu={true} />
- )}
-
- <FlatList
- keyExtractor={item => item.dateCreated.toString()}
- style={{
- width: '100%',
- alignSelf: 'center',
- height: '100%',
- }}
- contentContainerStyle={{
- height: '100%',
+ if (!isFocused) {
+ console.log('block rerender');
+ return <></>;
+ } else {
+ return (
+ <Container
+ bottomButtonOnPress={() => {
+ setDialog(true);
}}
- data={trash}
- ListEmptyComponent={
- <View
- style={{
- height: '80%',
- width: '100%',
- alignItems: 'center',
- alignSelf: 'center',
- justifyContent: 'center',
- opacity: 0.8,
- }}>
- <TrashPlaceHolder colors={colors} />
- <Text
- style={{
- color: colors.icon,
- fontSize: SIZE.md,
- fontFamily: WEIGHT.regular,
- marginTop: 20,
- }}>
- Deleted notes & notebooks appear here.
- </Text>
- <Text
+ bottomButtonText="Clear all trash">
+ <SelectionHeader />
+ {selectionMode ? null : (
+ <Header
+ colors={colors}
+ heading="Trash"
+ canGoBack={false}
+ menu={true}
+ />
+ )}
+
+ <FlatList
+ keyExtractor={item => item.dateCreated.toString()}
+ style={{
+ width: '100%',
+ alignSelf: 'center',
+ height: '100%',
+ }}
+ contentContainerStyle={{
+ height: '100%',
+ }}
+ data={trash}
+ ListEmptyComponent={
+ <View
style={{
- fontSize: SIZE.sm,
- color: colors.icon,
- marginTop: 20,
+ height: '80%',
+ width: '100%',
+ alignItems: 'center',
+ alignSelf: 'center',
+ justifyContent: 'center',
+ opacity: 0.8,
}}>
- Trash is empty
- </Text>
- </View>
- }
- renderItem={({item, index}) => (
- <SelectionWrapper item={item}>
- {item.type === 'note' ? (
- <NoteItem
- customStyle={{
- width: selectionMode ? w - 74 : '100%',
- marginHorizontal: 0,
- }}
- onLongPress={() => {
- if (!selectionMode) {
- updateSelectionList(item);
- }
+ <TrashPlaceHolder colors={colors} />
+ <Text
+ style={{
+ color: colors.icon,
+ fontSize: SIZE.md,
+ fontFamily: WEIGHT.regular,
+ marginTop: 20,
+ }}>
+ Deleted notes & notebooks appear here.
+ </Text>
+ <Text
+ style={{
+ fontSize: SIZE.sm,
+ color: colors.icon,
+ marginTop: 20,
+ }}>
+ Trash is empty
+ </Text>
+ </View>
+ }
+ renderItem={({item, index}) => (
+ <SelectionWrapper item={item}>
+ {item.type === 'note' ? (
+ <NoteItem
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
- changeSelectionMode(!selectionMode);
- }}
- item={item}
- index={index}
- isTrash={true}
- />
- ) : (
- <NotebookItem
- onLongPress={() => {
- if (!selectionMode) {
- updateSelectionList(item);
- }
+ changeSelectionMode(!selectionMode);
+ }}
+ item={item}
+ index={index}
+ isTrash={true}
+ />
+ ) : (
+ <NotebookItem
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
- changeSelectionMode(!selectionMode);
- }}
- customStyle={{
- width: selectionMode ? w - 74 : '100%',
- marginHorizontal: 0,
- }}
- item={item}
- isTrash={true}
- index={index}
- />
- )}
- </SelectionWrapper>
- )}
- />
+ changeSelectionMode(!selectionMode);
+ }}
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
+ item={item}
+ isTrash={true}
+ index={index}
+ />
+ )}
+ </SelectionWrapper>
+ )}
+ />
- <Dialog
- title="Empty Trash"
- visible={dialog}
- close={() => {
- setDialog(false);
- }}
- icon="trash"
- paragraph="Clearing all trash cannot be undone."
- positiveText="Clear"
- negativeText="Cancel"
- positivePress={async () => {
- await db.clearTrash();
- updateDB();
- ToastEvent.show('Trash cleared', 'success', 1000, () => {}, '');
- setDialog(false);
- }}
- negativePress={() => {
- setDialog(false);
- }}
- />
- </Container>
- );
+ <Dialog
+ title="Empty Trash"
+ visible={dialog}
+ close={() => {
+ setDialog(false);
+ }}
+ icon="trash"
+ paragraph="Clearing all trash cannot be undone."
+ positiveText="Clear"
+ negativeText="Cancel"
+ positivePress={async () => {
+ await db.clearTrash();
+ updateDB();
+ ToastEvent.show('Trash cleared', 'success', 1000, () => {}, '');
+ setDialog(false);
+ }}
+ negativePress={() => {
+ setDialog(false);
+ }}
+ />
+ </Container>
+ );
+ }
};
Trash.navigationOptions = {