Skip to content

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

handle effects on keyboard show and hide

ammarahm-ed03a33e81809a
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index fae93320c..28b1b5bce 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -10,6 +10,7 @@ import {
DeviceEventEmitter,
Platform,
Text,
+ Keyboard,
} from 'react-native';
import {COLOR_SCHEME, SIZE, opacity, WEIGHT, pv, ph} from './src/common/common';
import Icon from 'react-native-vector-icons/Ionicons';
@@ -27,6 +28,7 @@ const App = () => {
const [sidebar, setSidebar] = useState('30%');
const [isOpen, setOpen] = useState(false);
const [disableGestures, setDisableGesture] = useState(false);
+ const [buttonHide, setButtonHide] = useState(false);
useEffect(() => {
if (Platform.OS === 'android') {
StatusBar.setBackgroundColor('transparent');
@@ -83,6 +85,31 @@ const App = () => {
};
}, []);
+ useEffect(() => {
+ Keyboard.addListener('keyboardDidShow', () => {
+ setDisableGesture(true);
+ setButtonHide(true);
+ });
+ Keyboard.addListener('keyboardDidHide', () => {
+ setDisableGesture(false);
+ setTimeout(() => {
+ setButtonHide(false);
+ }, 500);
+ });
+ return () => {
+ Keyboard.removeListener('keyboardDidShow', () => {
+ setDisableGesture(true);
+ setButtonHide(true);
+ });
+ Keyboard.removeListener('keyboardDidHide', () => {
+ setDisableGesture(false);
+ setTimeout(() => {
+ setButtonHide(false);
+ }, 500);
+ });
+ };
+ }, []);
+
return (
<View
style={{
@@ -121,10 +148,19 @@ const App = () => {
isOpen={isOpen}
disableGestures={disableGestures}
bounceBackOnOverdraw={false}
+ contentContainerStyle={{
+ opacity: 0,
+ }}
onChange={args => {
setOpen(args);
}}
- menu={<Menu colors={colors} close={() => setOpen(false)} />}
+ menu={
+ <Menu
+ hide={buttonHide}
+ colors={colors}
+ close={() => setOpen(false)}
+ />
+ }
openMenuOffset={w / 1.5}>
<AppContainer
style={{
diff --git a/apps/mobile/src/components/Menu/index.js b/apps/mobile/src/components/Menu/index.js
index 877a0c387..4b0ee4ad3 100644
--- a/apps/mobile/src/components/Menu/index.js
+++ b/apps/mobile/src/components/Menu/index.js
@@ -25,11 +25,11 @@ import Icon from 'react-native-vector-icons/Feather';
import {getElevation, w, h, Toast} from '../../utils/utils';
-export const Menu = ({colors, close = () => {}}) => (
+export const Menu = ({colors, close = () => {}, hide}) => (
<SafeAreaView
style={{
height: '100%',
-
+ opacity: hide ? 0 : 1,
backgroundColor: colors.navbg,
}}>
<ScrollView
diff --git a/apps/mobile/src/components/NotesList/index.js b/apps/mobile/src/components/NotesList/index.js
index 02dd9d63c..51e4a0315 100644
--- a/apps/mobile/src/components/NotesList/index.js
+++ b/apps/mobile/src/components/NotesList/index.js
@@ -27,7 +27,7 @@ import NoteItem from '../NoteItem';
import NavigationService from '../../services/NavigationService';
import {storage} from '../../../App';
-export const NotesList = ({keyword, searchResults}) => {
+export const NotesList = ({keyword, searchResults, margin, onScroll}) => {
const [colors, setColors] = useState(COLOR_SCHEME);
return (
@@ -51,11 +51,16 @@ export const NotesList = ({keyword, searchResults}) => {
</Text>
</View>
}
+ onScroll={event => {
+ y = event.nativeEvent.contentOffset.y;
+ onScroll(y);
+ }}
ListHeaderComponent={
<>
<Text
style={{
fontSize: SIZE.lg,
+ marginTop: margin,
fontFamily: WEIGHT.medium,
color: colors.pri,
paddingHorizontal: Platform.isPad ? '2.5%' : '5%',
diff --git a/apps/mobile/src/components/SearchInput/index.js b/apps/mobile/src/components/SearchInput/index.js
index 065378f27..be7213746 100644
--- a/apps/mobile/src/components/SearchInput/index.js
+++ b/apps/mobile/src/components/SearchInput/index.js
@@ -76,6 +76,7 @@ export const Search = props => {
<Icon
style={{paddingRight: Platform.isPad ? '1.25%' : '2.5%'}}
onPress={() => {
+ props.clear();
props.value.length > 0 ? props.clearSearch() : null;
inputRef.current.setNativeProps({
text: '',
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 2045d3610..b70918079 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -7,6 +7,7 @@ import {
View,
KeyboardAvoidingView,
Text,
+ Keyboard,
} from 'react-native';
import {COLOR_SCHEME, opacity, pv, br, SIZE, WEIGHT} from '../../common/common';
import {styles} from './styles';
@@ -29,6 +30,7 @@ export const Home = ({navigation}) => {
const [update, setUpdate] = useState(0);
const [hideHeader, setHideHeader] = useState(false);
const [margin, setMargin] = useState(150);
+ const [buttonHide, setButtonHide] = useState(false);
let offsetY = 0;
let countUp = 0;
let countDown = 0;
@@ -84,10 +86,30 @@ export const Home = ({navigation}) => {
}, 10);
}
};
+ useEffect(() => {
+ Keyboard.addListener('keyboardDidShow', () => {
+ setButtonHide(true);
+ });
+ Keyboard.addListener('keyboardDidHide', () => {
+ setTimeout(() => {
+ setButtonHide(false);
+ }, 600);
+ });
+ return () => {
+ Keyboard.removeListener('keyboardDidShow', () => {
+ setButtonHide(true);
+ });
+ Keyboard.removeListener('keyboardDidHide', () => {
+ setTimeout(() => {
+ setButtonHide(false);
+ }, 600);
+ });
+ };
+ }, []);
return Platform.isPad ? (
- <SafeAreaView style={[styles.container]}>
- <KeyboardAvoidingView>
+ <SafeAreaView style={[styles.container, {backgroundColor: colors.bg}]}>
+ <KeyboardAvoidingView style={{backgroundColor: colors.bg}}>
<NavigationEvents
onWillFocus={() => {
DeviceEventEmitter.emit('openSidebar');
@@ -155,6 +177,7 @@ export const Home = ({navigation}) => {
searchHeight = height;
setMarginTop();
}}
+ clear={() => setText('')}
hide={hideHeader}
onChangeText={onChangeText}
onSubmitEditing={onSubmitEditing}
@@ -166,7 +189,25 @@ export const Home = ({navigation}) => {
/>
</View>
{hidden ? (
- <NotesList searchResults={searchResults} keyword={text} />
+ <NotesList
+ margin={margin}
+ onScroll={y => {
+ 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;
+ }}
+ searchResults={searchResults}
+ keyword={text}
+ />
) : (
<RecentList
onScroll={y => {
@@ -187,40 +228,42 @@ export const Home = ({navigation}) => {
update={update}
/>
)}
- <TouchableOpacity
- onPress={() => {
- NavigationService.navigate('Editor');
- }}
- activeOpacity={opacity}
- style={{
- width: '90%',
- alignSelf: 'center',
- borderRadius: br,
- backgroundColor: colors.accent,
- justifyContent: 'center',
- alignItems: 'center',
- marginBottom: 20,
- }}>
- <View
+ {buttonHide ? null : (
+ <TouchableOpacity
+ onPress={() => {
+ NavigationService.navigate('Editor');
+ }}
+ activeOpacity={opacity}
style={{
- justifyContent: 'space-between',
+ width: '90%',
+ alignSelf: 'center',
+ borderRadius: br,
+ backgroundColor: colors.accent,
+ justifyContent: 'center',
alignItems: 'center',
- flexDirection: 'row',
- width: '100%',
- padding: pv,
- paddingVertical: pv + 5,
+ marginBottom: 20,
}}>
- <Text
+ <View
style={{
- fontSize: SIZE.md,
- color: 'white',
- fontFamily: WEIGHT.bold,
+ justifyContent: 'space-between',
+ alignItems: 'center',
+ flexDirection: 'row',
+ width: '100%',
+ padding: pv,
+ paddingVertical: pv + 5,
}}>
- Add a new note
- </Text>
- <Icon name="plus" color="white" size={SIZE.lg} />
- </View>
- </TouchableOpacity>
+ <Text
+ style={{
+ fontSize: SIZE.md,
+ color: 'white',
+ fontFamily: WEIGHT.bold,
+ }}>
+ Add a new note
+ </Text>
+ <Icon name="plus" color="white" size={SIZE.lg} />
+ </View>
+ </TouchableOpacity>
+ )}
</KeyboardAvoidingView>
</SafeAreaView>
);