Skip to content

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

improve gesture animation

ammarahm-edc172877303e3
diff --git a/apps/mobile/src/components/tabs/index.tsx b/apps/mobile/src/components/tabs/index.tsx
index 8f166ef0e..29ff372f5 100644
--- a/apps/mobile/src/components/tabs/index.tsx
+++ b/apps/mobile/src/components/tabs/index.tsx
@@ -6,17 +6,20 @@ import React, {
useRef,
useState
} from 'react';
-import { BackHandler, ViewProps } from 'react-native';
-import { Gesture, GestureDetector, State } from 'react-native-gesture-handler';
+import { BackHandler, Platform, ViewProps } from 'react-native';
+import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import Animated, {
runOnJS,
useAnimatedReaction,
useAnimatedStyle,
useSharedValue,
withSpring,
+ WithSpringConfig,
withTiming
} from 'react-native-reanimated';
import { useSettingStore } from '../../stores/use-setting-store';
+import { eSendEvent } from '../../services/event-manager';
+import { eClearEditor } from '../../utils/events';
interface TabProps extends ViewProps {
dimensions: { width: number; height: number };
@@ -62,16 +65,16 @@ export const FluidTabs = forwardRef<TabsRef, TabProps>(
const [disabled, setDisabled] = useState(false);
const node = useRef<Animated.View>(null);
const containerWidth = widths ? widths.a + widths.b + widths.c : dimensions.width;
- console.log(containerWidth, dimensions.width);
+
const drawerPosition = 0;
const homePosition = widths.a;
const editorPosition = widths.a + widths.b;
const isSmallTab = deviceMode === 'smallTablet';
const isLoaded = useRef(false);
const prevWidths = useRef(widths);
+ const isIPhone = Platform.OS === 'ios';
useEffect(() => {
- console.log(deviceMode);
if (introCompleted) {
if (deviceMode === 'tablet' || fullscreen) {
translateX.value = 0;
@@ -169,7 +172,7 @@ export const FluidTabs = forwardRef<TabsRef, TabProps>(
result => {
if (setDisabled) {
if (result === 2) {
- runOnJS(setDisabled)(true);
+ runOnJS(setDisabled)(!isIPhone);
} else {
runOnJS(setDisabled)(false);
}
@@ -190,6 +193,12 @@ export const FluidTabs = forwardRef<TabsRef, TabProps>(
[]
);
+ const clearEditor = () => {
+ setTimeout(() => {
+ eSendEvent(eClearEditor);
+ }, 300);
+ };
+
const gesture = Gesture.Pan()
.maxPointers(1)
.enabled(enabled && !disabled)
@@ -222,24 +231,28 @@ export const FluidTabs = forwardRef<TabsRef, TabProps>(
let value = translateX.value + event.changeX * -1;
if (
value < 0 ||
- currentTab.value === 2 ||
- value > editorPosition ||
- (value >= homePosition && isSmallTab)
+ (currentTab.value === 2 && Platform.OS === 'android') ||
+ (currentTab.value === 2 && gestureStartValue.value.x > 25 && Platform.OS === 'ios') ||
+ (value >= homePosition && isSmallTab) ||
+ value > editorPosition
)
return;
translateX.value = value;
})
.onEnd(event => {
- if (currentTab.value === 2) return;
+ if (currentTab.value === 2 && Platform.OS === 'android') return;
let velocityX = event.velocityX < 0 ? event.velocityX * -1 : event.velocityX;
let isSwipeLeft = startX.value > translateX.value;
let finalValue = isSwipeLeft
? translateX.value - velocityX / 40.0
: translateX.value + velocityX / 40.0;
- const animationConfig = {
- velocity: event.velocityX,
- mass: 0.01
+ const animationConfig: WithSpringConfig = {
+ velocity: velocityX,
+ mass: 0.5,
+ overshootClamping: true,
+ damping: 800,
+ stiffness: 800
};
if (finalValue < homePosition) {
@@ -273,6 +286,19 @@ export const FluidTabs = forwardRef<TabsRef, TabProps>(
}
}
+ if (currentTab.value === 2) {
+ if (finalValue < editorPosition - 100 && isSwipeLeft) {
+ translateX.value = withSpring(homePosition, animationConfig);
+ currentTab.value = 1;
+ isDrawerOpen.value = false;
+ runOnJS(clearEditor)();
+ } else {
+ translateX.value = withSpring(editorPosition, animationConfig);
+ currentTab.value = 2;
+ }
+ return;
+ }
+
runOnJS(onDrawerStateChange)(false);
translateX.value = withSpring(homePosition, animationConfig);
currentTab.value = 1;
diff --git a/apps/mobile/src/screens/editor/index.tsx b/apps/mobile/src/screens/editor/index.tsx
index f115a2e84..4ccb8091f 100755
--- a/apps/mobile/src/screens/editor/index.tsx
+++ b/apps/mobile/src/screens/editor/index.tsx
@@ -139,7 +139,7 @@ const Editor = React.memo(
allowUniversalAccessFromFileURLs={true}
originWhitelist={['*']}
source={{
- uri: __DEV__ ? EDITOR_URI : EDITOR_URI
+ uri: __DEV__ ? 'http://localhost:3000/index.html' : EDITOR_URI
}}
style={style}
autoManageStatusBarEnabled={false}
diff --git a/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts b/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
index 6f5bd8da1..ba47e31e0 100644
--- a/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
+++ b/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
@@ -1,7 +1,12 @@
/* eslint-disable no-case-declarations */
/* eslint-disable @typescript-eslint/no-var-requires */
import { useCallback, useEffect, useRef } from 'react';
-import { BackHandler, InteractionManager, NativeEventSubscription } from 'react-native';
+import {
+ BackHandler,
+ DeviceEventEmitter,
+ InteractionManager,
+ NativeEventSubscription
+} from 'react-native';
import { WebViewMessageEvent } from 'react-native-webview';
import useKeyboard from '../../../utils/hooks/use-keyboard';
import { DDS } from '../../../services/device-detection';
@@ -34,6 +39,7 @@ import { NoteType } from '../../../utils/types';
import { useDragState } from '../../settings/editor/state';
import { EditorMessage, EditorProps, useEditorType } from './types';
import { EditorEvents, editorState } from './utils';
+import { executeNativeBackPress } from 'react-native-screens';
export const EventTypes = {
selection: 'editor-event:selection',
@@ -127,7 +133,7 @@ export const useEditorEvents = (
if (!editor) return null;
useEffect(() => {
- console.log('settings', fullscreen);
+ console.log('keyboardShown', keyboardShown);
editor.commands.setSettings({
deviceMode: deviceMode || 'mobile',
fullscreen: fullscreen || false,
@@ -193,7 +199,6 @@ export const useEditorEvents = (
}
});
}, []);
-
const onCallClear = useCallback(async (value: string) => {
if (value === 'removeHandler') {
if (handleBack.current) {