A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
chore: refactor & cleanup
ammarahm-ed67f4867acb10
diff --git a/apps/mobile/src/components/tabs/index.js b/apps/mobile/src/components/tabs/index.jsdeleted file mode 100644index 3a4d8c238..000000000--- a/apps/mobile/src/components/tabs/index.js+++ /dev/null@@ -1,282 +0,0 @@-import React, { Component, createRef } from 'react';-import { Platform } from 'react-native';-import { Keyboard } from 'react-native';-import { FlatList, TextInput, View } from 'react-native';-import { DDS } from '../../services/device-detection';-import { editing } from '../../utils';--export default class Tabs extends Component {- constructor(props) {- super(props);- this.listRef = createRef();- this.scrollOffset = this.props.offsets.a;- this.page = 0;- this.nextPage = 0;- this.currentDrawerState = false;- this.inputElement = createRef();- this.keyboardState = false;- this.scrollTimeout = null;- this.scrollEnabled = true;- this.responderAllowedScroll = false;- this.moved = false;- this.lastOffset = this.props.offsets.a;- this.locked = false;- }- renderItem = ({ item, index }) => this.props.items[index];-- onMoveShouldSetResponder = event => {- if (this.locked) return false;- if (this.responderAllowedScroll) return false;- this.lastOffset = this.scrollOffset;- let x = event.nativeEvent.pageX;- this.hideKeyboardIfVisible();- let cOffset = this.scrollOffset.toFixed(0);- let pOffset = this.props.offsets.b.toFixed(0);- let aOffset = this.props.offsets.a.toFixed(0);- let page0Width = pOffset - aOffset;-- if (- (this.page === 0 && !this.currentDrawerState && x > 100 && x < page0Width - 100) ||- DDS.isLargeTablet()- ) {- this.responderAllowedScroll = false;- this.setScrollEnabled(false);- return false;- }-- if (cOffset > pOffset - 50 || DDS.isSmallTab) {- this.responderAllowedScroll = false;- this.setScrollEnabled(false);- return false;- }-- this.setScrollEnabled(true);- this.responderAllowedScroll = true;- return false;- };-- openDrawer = () => {- if (this.page === 0) {- if (this.scrollOffset === 0) {- this.goToIndex(1);- this.currentDrawerState = false;- } else {- this.currentDrawerState = true;- this.goToIndex(0);- }- this.props.onDrawerStateChange && this.props.onDrawerStateChange(this.currentDrawerState);- }- };-- closeDrawer = () => {- if (this.page === 0) {- this.goToIndex(1);- this.currentDrawerState = false;- this.props.onDrawerStateChange && this.props.onDrawerStateChange(this.currentDrawerState);- }- };-- hideKeyboardIfVisible(close) {- if (!close && this.nextPage === 1) return;- if (Platform.OS === 'ios') return;- if (editing.movedAway) return;-- if (- (editing.keyboardState || editing.isFocused) &&- this.scrollOffset < this.props.offsets.b - 50- ) {- editing.keyboardState = false;- Keyboard.dismiss();- }- }-- goToIndex(index, animated = true) {- if (this.scrollEndTimeout) {- clearTimeout(this.scrollEndTimeout);- this.scrollEndTimeout = null;- }- let offset = 0;- if (index === 1) {- this.nextPage = 0;- offset = this.props.offsets.a;- this.setScrollEnabled(true);- } else if (index === 2) {- this.nextPage = 1;- offset = this.props.offsets.b;- } else {- offset = 0;- this.nextPage = 0;- }-- this.listRef.current?.scrollToOffset({- offset: offset,- animated: animated- });- }-- setScrollEnabled = enabled => {- this.scrollEnabled = enabled;- this.locked = !enabled;- this.listRef.current?.getNativeScrollRef().setNativeProps({- scrollEnabled: enabled- });- };-- unlock = () => {- this.locked = false;- };-- onTouchEnd = () => {- this.locked = false;- this.responderAllowedScroll = false;- this.setScrollEnabled(true);- };-- onScroll = event => {- this.moved = true;- this.scrollOffset = event.nativeEvent.contentOffset.x;- if (this.scrollEndTimeout) {- clearTimeout(this.scrollEndTimeout);- this.scrollEndTimeout = null;- }-- if (this.page === 1 && this.scrollOffset < this.props.offsets.b - 100) {- this.nextPage = 0;- } else {- this.nextPage = 1;- }- this.props.onScroll(this.scrollOffset);- if (this.scrollTimeout) {- clearTimeout(this.scrollTimeout);- this.scrollTimeout = null;- }- this.scrollTimeout = setTimeout(() => {- if (this.scrollOffset !== this.props.offsets.a && this.page === 1 && !this.scrollEnabled) {- this.goToIndex(2, false);- }- }, 300);- };-- goToPage = page => {- if (this.scrollEndTimeout) {- clearTimeout(this.scrollEndTimeout);- this.scrollEndTimeout = null;- }- this.nextPage = page;- if (page === 0) {- this.scrollOffset = this.props.offsets.a;- this.goToIndex(1);- } else if (page === 1) {- this.goToIndex(2);- }- if (this.page !== page) {- this.props.onChangeTab({ i: page, from: this.page });- this.page = page;- }- };-- keyExtractor = (item, index) => item;-- scrollEndTimeout = null;-- onScrollEnd = () => {- if (this.scrollEndTimeout) {- clearTimeout(this.scrollEndTimeout);- this.scrollEndTimeout = null;- }- this.moved = false;- this.responderAllowedScroll = false;- let page = 0;-- if (this.scrollOffset > this.props.offsets.b - 100) {- page = 1;- this.nextPage = 1;- } else {- this.nextPage = 0;- }-- let drawerState = page === 0 && this.scrollOffset < 150;- if (drawerState !== this.currentDrawerState) {- this.currentDrawerState = drawerState;- this.props.onDrawerStateChange && this.props.onDrawerStateChange(this.currentDrawerState);- }- this.props.toggleOverlay(- Math.floor(this.scrollOffset) < Math.floor(this.props.offsets.a - 10) ? true : false- );- if (this.page !== page) {- this.scrollEndTimeout = setTimeout(() => {- this.props.onChangeTab({ i: page, from: this.page });- this.page = page;- }, 50);- }- };-- onListTouchEnd = event => {- if (this.locked) return;- if (this.lastOffset < 30 && event) {- let width = this.props.dimensions.width;- let px = event.nativeEvent.pageX;- if (px > width * 0.75 || (DDS.isSmallTab && px > this.props.widths.a)) {- this.goToIndex(1);- this.currentDrawerState = false;- this.props.onDrawerStateChange && this.props.onDrawerStateChange(this.currentDrawerState);- }- }- };-- render() {- return (- <View- onTouchEnd={this.onTouchEnd}- onMoveShouldSetResponderCapture={this.onMoveShouldSetResponder}- onStartShouldSetResponderCapture={this.onMoveShouldSetResponder}- style={{- flex: 1- }}- >- <TextInput- ref={this.inputElement}- style={{ height: 1, padding: 0, width: 1, position: 'absolute' }}- blurOnSubmit={false}- />- <FlatList- ref={this.listRef}- horizontal- onMomentumScrollEnd={this.onScrollEnd}- onScrollAnimationEnd={this.onScrollEnd}- keyExtractor={this.keyExtractor}- onScroll={this.onScroll}- bounces={false}- bouncesZoom={false}- onTouchEnd={this.onListTouchEnd}- initialNumToRender={100}- alwaysBounceHorizontal={false}- scrollToOverflowEnabled={false}- scrollsToTop={false}- scrollEventThrottle={5}- overScrollMode="never"- maxToRenderPerBatch={100}- directionalLockEnabled- keyboardDismissMode="none"- removeClippedSubviews={false}- keyboardShouldPersistTaps="always"- showsHorizontalScrollIndicator={false}- disableIntervalMomentum={true}- disableVirtualization={true}- decelerationRate="fast"- snapToAlignment="start"- snapToOffsets={[this.props.offsets.a, this.props.offsets.b, this.props.offsets.c]}- contentOffset={{- x: editing.movedAway ? this.props.offsets.a : this.props.offsets.b- }}- data={['drawer', 'navigation', 'editor']}- renderItem={this.renderItem}- />- </View>- );- }-}--Tabs.defaultProps = {- onDrawerStateChange: () => {}-};diff --git a/apps/mobile/src/components/tabs/new.tsx b/apps/mobile/src/components/tabs/index.tsxsimilarity index 95%rename from apps/mobile/src/components/tabs/new.tsxrename to apps/mobile/src/components/tabs/index.tsxindex 918a6fb09..200549398 100644--- a/apps/mobile/src/components/tabs/new.tsx+++ b/apps/mobile/src/components/tabs/index.tsx@@ -83,12 +83,10 @@ export const NewTabs = forwardRef<TabsRef, TabProps>(},unlock: () => {forcedLock.value = false;- console.log('forced lock status', forcedLock.value);return false;},lock: () => {forcedLock.value = true;- console.log('forced lock status', forcedLock.value);return true;},openDrawer: () => {@@ -171,13 +169,11 @@ export const NewTabs = forwardRef<TabsRef, TabProps>(const animationConfig = {velocity: event.velocityX,- overshootClamping: true,- stiffness: 200,- mass: 0.1+ mass: 0.01};if (finalValue < homePosition) {- if (isSwipeLeft && finalValue < homePosition - 150) {+ if (isSwipeLeft && finalValue < homePosition - 100) {translateX.value = withSpring(0, animationConfig);isDrawerOpen.value = true;currentTab.value = 1;@@ -189,7 +185,7 @@ export const NewTabs = forwardRef<TabsRef, TabProps>(currentTab.value = 1;runOnJS(onDrawerStateChange)(false);return;- } else if (!isSwipeLeft && finalValue < 150) {+ } else if (!isSwipeLeft && finalValue < 100) {translateX.value = withSpring(0, animationConfig);isDrawerOpen.value = true;currentTab.value = 1;diff --git a/apps/mobile/src/navigation/tabsholder.js b/apps/mobile/src/navigation/tabsholder.jsindex 0faaf9dc9..bf75e357f 100644--- a/apps/mobile/src/navigation/tabsholder.js+++ b/apps/mobile/src/navigation/tabsholder.js@@ -6,7 +6,7 @@ import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-naimport { useSafeAreaInsets } from 'react-native-safe-area-context';import { notesnook } from '../../e2e/test.ids';import { SideMenu } from '../components/side-menu';-import { NewTabs } from '../components/tabs/new';+import { NewTabs } from '../components/tabs';import { EditorWrapper } from '../screens/editor/EditorWrapper';import { checkStatus, EditorWebView, getNote } from '../screens/editor/Functions';import tiny from '../screens/editor/tiny/tiny';diff --git a/apps/mobile/src/utils/globalrefs.ts b/apps/mobile/src/utils/globalrefs.tsindex c4eb99622..648a82c40 100644--- a/apps/mobile/src/utils/globalrefs.ts+++ b/apps/mobile/src/utils/globalrefs.ts@@ -1,7 +1,7 @@import { createNavigationContainerRef } from '@react-navigation/native';import { createRef } from 'react';import { TextInput, View } from 'react-native';-import { TabsRef } from '../components/tabs/new';+import { TabsRef } from '../components/tabs';export const inputRef = createRef<TextInput>();export const rootNavigatorRef = createNavigationContainerRef();