From 1ed4cd3682783defa6a366d17e0743831d26fd69 Mon Sep 17 00:00:00 2001 From: Kirill Zyusko Date: Fri, 23 Aug 2024 11:18:39 +0200 Subject: [PATCH] fix: cycle dependencies (#563) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 📜 Description Fixed cycle dependencies in the code. ## 💡 Motivation and Context Cycle dependencies may lead to unpredictable results especially if you have many of them. To fix them I used `eslint` rule - it's quite effective and we don't need to change CI pipelines etc. Plus we can monitor such cycles contioniously! Closes https://github.com/kirillzyusko/react-native-keyboard-controller/issues/562 ## 📢 Changelog ### JS - reorganized imports to avoid cycle deps; - added new eslint rule usage. ## 🤔 How Has This Been Tested? Tested on e2e tests on CI 🙂 ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed --- .eslintrc.cjs | 1 + src/components/KeyboardAvoidingView/hooks.ts | 6 ++---- src/components/KeyboardAvoidingView/index.tsx | 2 +- src/components/KeyboardAwareScrollView/index.tsx | 2 +- .../KeyboardAwareScrollView/useSmoothKeyboardHandler.ts | 2 +- src/components/KeyboardStickyView/index.tsx | 2 +- src/components/KeyboardToolbar/index.tsx | 8 ++------ 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index dc8cc54508..803865a182 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -108,6 +108,7 @@ module.exports = { "newlines-between": "always", }, ], + "import/no-cycle": ["error", { maxDepth: "∞" }], // jest "jest/expect-expect": [ "warn", diff --git a/src/components/KeyboardAvoidingView/hooks.ts b/src/components/KeyboardAvoidingView/hooks.ts index 1033617604..399695f079 100644 --- a/src/components/KeyboardAvoidingView/hooks.ts +++ b/src/components/KeyboardAvoidingView/hooks.ts @@ -1,9 +1,7 @@ import { useSharedValue } from "react-native-reanimated"; -import { - useKeyboardContext, - useKeyboardHandler, -} from "react-native-keyboard-controller"; +import { useKeyboardContext } from "../../context"; +import { useKeyboardHandler } from "../../hooks"; export const useKeyboardAnimation = () => { const { reanimated } = useKeyboardContext(); diff --git a/src/components/KeyboardAvoidingView/index.tsx b/src/components/KeyboardAvoidingView/index.tsx index 4a2c01ac97..c8303c072a 100644 --- a/src/components/KeyboardAvoidingView/index.tsx +++ b/src/components/KeyboardAvoidingView/index.tsx @@ -8,7 +8,7 @@ import Reanimated, { useSharedValue, } from "react-native-reanimated"; -import { useWindowDimensions } from "react-native-keyboard-controller"; +import { useWindowDimensions } from "../../hooks"; import { useKeyboardAnimation } from "./hooks"; diff --git a/src/components/KeyboardAwareScrollView/index.tsx b/src/components/KeyboardAwareScrollView/index.tsx index ca15d19d26..ddab855daa 100644 --- a/src/components/KeyboardAwareScrollView/index.tsx +++ b/src/components/KeyboardAwareScrollView/index.tsx @@ -14,7 +14,7 @@ import { useFocusedInputHandler, useReanimatedFocusedInput, useWindowDimensions, -} from "react-native-keyboard-controller"; +} from "../../hooks"; import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler"; import { debounce, scrollDistanceWithRespectToSnapPoints } from "./utils"; diff --git a/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts b/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts index 8966470996..645835ed8c 100644 --- a/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +++ b/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts @@ -6,7 +6,7 @@ import { withTiming, } from "react-native-reanimated"; -import { useKeyboardHandler } from "react-native-keyboard-controller"; +import { useKeyboardHandler } from "../../hooks"; const IS_ANDROID_ELEVEN_OR_HIGHER = Platform.OS === "android" && Platform.Version >= 30; diff --git a/src/components/KeyboardStickyView/index.tsx b/src/components/KeyboardStickyView/index.tsx index 9a873f38a6..387062e0c3 100644 --- a/src/components/KeyboardStickyView/index.tsx +++ b/src/components/KeyboardStickyView/index.tsx @@ -4,7 +4,7 @@ import Reanimated, { useAnimatedStyle, } from "react-native-reanimated"; -import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller"; +import { useReanimatedKeyboardAnimation } from "../../hooks"; import type { View, ViewProps } from "react-native"; diff --git a/src/components/KeyboardToolbar/index.tsx b/src/components/KeyboardToolbar/index.tsx index 95ced0b44e..f178690fb0 100644 --- a/src/components/KeyboardToolbar/index.tsx +++ b/src/components/KeyboardToolbar/index.tsx @@ -1,13 +1,9 @@ import React, { useCallback, useEffect, useMemo, useState } from "react"; import { StyleSheet, Text, View } from "react-native"; -import { - FocusedInputEvents, - KeyboardStickyView, -} from "react-native-keyboard-controller"; - -import { KeyboardController } from "../../bindings"; +import { FocusedInputEvents, KeyboardController } from "../../bindings"; import useColorScheme from "../hooks/useColorScheme"; +import KeyboardStickyView from "../KeyboardStickyView"; import Arrow from "./Arrow"; import Button from "./Button";