From 80f88f85badc5fe255c5fc824fedcdb21d4f1593 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Sat, 10 Feb 2024 18:56:33 +0500 Subject: [PATCH] mobile: fix notebooks & colors --- .../mobile/app/components/container/index.tsx | 16 +- .../components/dialogs/color-picker/index.tsx | 340 +++---- .../mobile/app/components/properties/index.js | 5 +- .../app/components/sheet-provider/index.js | 5 +- .../components/sheets/add-notebook/index.tsx | 6 +- .../components/sheets/move-notes/movenote.tsx | 94 +- .../sheets/notebook-sheet/index.tsx | 169 ++-- apps/mobile/app/hooks/use-actions.tsx | 12 +- .../mobile/app/navigation/navigation-stack.js | 1 - apps/mobile/app/package.json | 10 +- .../mobile/app/stores/item-selection-store.ts | 20 +- apps/mobile/native/package.json | 1 + apps/mobile/package-lock.json | 889 ++++++++++-------- apps/mobile/package.json | 10 +- ...eact-native-wheel-color-picker+1.3.1.patch | 18 + 15 files changed, 786 insertions(+), 810 deletions(-) create mode 100644 apps/mobile/patches/react-native-wheel-color-picker+1.3.1.patch diff --git a/apps/mobile/app/components/container/index.tsx b/apps/mobile/app/components/container/index.tsx index fc1e61f0e..9cf81ba8b 100644 --- a/apps/mobile/app/components/container/index.tsx +++ b/apps/mobile/app/components/container/index.tsx @@ -18,27 +18,25 @@ along with this program. If not, see . */ import React, { PropsWithChildren } from "react"; -import { KeyboardAvoidingView, Platform } from "react-native"; +import { Platform, View, useWindowDimensions } from "react-native"; import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets"; -import useIsFloatingKeyboard from "../../hooks/use-is-floating-keyboard"; export const Container = ({ children }: PropsWithChildren) => { - const floating = useIsFloatingKeyboard(); const insets = useGlobalSafeAreaInsets(); + const dimensions = useWindowDimensions(); return ( - {children} - + ); }; diff --git a/apps/mobile/app/components/dialogs/color-picker/index.tsx b/apps/mobile/app/components/dialogs/color-picker/index.tsx index e68d7dfb9..14e1c8af7 100644 --- a/apps/mobile/app/components/dialogs/color-picker/index.tsx +++ b/apps/mobile/app/components/dialogs/color-picker/index.tsx @@ -16,131 +16,27 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ +import { Color } from "@notesnook/core"; import { useThemeColors } from "@notesnook/theme"; import React, { useRef, useState } from "react"; import { TextInput, View } from "react-native"; -import { FlashList } from "react-native-actions-sheet/dist/src/views/FlashList"; -import Icon from "react-native-vector-icons/MaterialCommunityIcons"; +import ColorPickerWheel from "react-native-wheel-color-picker"; import { db } from "../../../common/database"; +import { useStoredRef } from "../../../hooks/use-stored-ref"; import { ToastManager } from "../../../services/event-manager"; import { useMenuStore } from "../../../stores/use-menu-store"; import { useRelationStore } from "../../../stores/use-relation-store"; import { useSettingStore } from "../../../stores/use-setting-store"; -import { SIZE } from "../../../utils/size"; import BaseDialog from "../../dialog/base-dialog"; import DialogContainer from "../../dialog/dialog-container"; import { Toast } from "../../toast"; import { Button } from "../../ui/button"; import Input from "../../ui/input"; import { PressableButton } from "../../ui/pressable"; -import { Color } from "@notesnook/core"; -const arrayOfColors = [ - "#FF5733", - "#33FF57", - "#339DFF", - "#FF33E9", - "#E9FF33", - "#FF3395", - "#95FF33", - "#FF3369", - "#6933FF", - "#33FFC7", - "#FF5733", - "#33FF57", - "#339DFF", - "#FF33E9", - "#E9FF33", - "#FF3395", - "#95FF33", - "#FF3369", - "#6933FF", - "#33FFC7", - "#FF5733", - "#33FF57", - "#339DFF", - "#FF33E9", - "#E9FF33", - "#FF3395", - "#95FF33", - "#FF3369", - "#6933FF", - "#33FFC7", - "#FF5733", - "#33FF57", - "#339DFF", - "#FF33E9", - "#E9FF33", - "#FF3395", - "#95FF33", - "#FF3369", - "#6933FF", - "#33FFC7", - "#FF5733", - "#33FF57", - "#339DFF", - "#FF33E9", - "#E9FF33", - "#FF3395", - "#95FF33", - "#FF3369", - "#6933FF", - "#33FFC7", - "#FF5733", - "#33FF57", - "#339DFF", - "#FF33E9", - "#E9FF33", - "#FF3395", - "#95FF33", - "#FF3369", - "#6933FF", - "#33FFC7", - "#FF5733", - "#33FF57", - "#339DFF", - "#FF33E9", - "#E9FF33", - "#FF3395", - "#95FF33", - "#FF3369", - "#6933FF", - "#33FFC7", - "#FF5733", - "#33FF57", - "#339DFF", - "#FF33E9", - "#E9FF33", - "#FF3395", - "#95FF33", - "#FF3369", - "#6933FF", - "#33FFC7", - "#FF5733", - "#33FF57", - "#339DFF", - "#FF33E9", - "#E9FF33", - "#FF3395", - "#95FF33", - "#FF3369", - "#6933FF", - "#33FFC7" -]; + const HEX_COLOR_REGEX_ALPHA = /^#(?:(?:[\da-fA-F]{3}){1,2}|(?:[\da-fA-F]{4}){1,2})$/; -const convertToColorObjects = (colors: string[]) => { - const colorObjects = []; - for (let i = 0; i < colors.length; i += 3) { - colorObjects.push({ - colorOne: colors[i], - colorTwo: colors[i + 1], - colorThree: colors[i + 2] - }); - } - return colorObjects; -}; - const ColorPicker = ({ visible, setVisible, @@ -154,43 +50,7 @@ const ColorPicker = ({ const { colors } = useThemeColors(); const inputRef = useRef(null); const title = useRef(); - - const renderItem = ({ - item - }: { - item: { colorOne: string; colorTwo: string; colorThree: string }; - }) => ( - - {Object.keys(item).map((key) => ( - { - const color = item[key as keyof typeof item]; - setSelectedColor(color); - inputRef.current?.setNativeProps({ - placeholder: color, - text: color - }); - }} - > - {selectedColor === item[key as keyof typeof item] ? ( - - ) : null} - - ))} - - ); + const colorRef = useStoredRef("color-ref", "#f0f0f0"); return ( - - - + - { - if (HEX_COLOR_REGEX_ALPHA.test(value)) { - setSelectedColor(value); - inputRef.current?.setNativeProps({ - placeholder: value, - text: value - }); - } - }} - /> - { + if (color === selectedColor) return; + colorRef.current = color; + setSelectedColor(color); + inputRef.current?.setNativeProps({ + placeholder: color, + text: color + }); }} + useNativeLayout={true} + autoResetSlider={true} + color={colorRef.current} + sliderSize={30} + thumbSize={25} + shadeWheelThumb + shadeSliderThumb={true} + swatchesOnly={false} + swatches={false} + useNativeDriver={true} /> - { - title.current = value; + + > + + { + if (HEX_COLOR_REGEX_ALPHA.test(value)) { + colorRef.current = value; + setSelectedColor(value); + } + }} + defaultValue={colorRef.current} + /> + + -