From d136d51848b3eb3d0a0693b19df28199925425ad Mon Sep 17 00:00:00 2001 From: Nathanael Martins <49047480+natemartins@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:21:42 +0100 Subject: [PATCH 1/2] fix: Support for defaultProps will be removed from function components in a future major release --- package.json | 5 +++-- src/toggle.tsx | 28 ++++++++++------------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 3f0e007..60de668 100644 --- a/package.json +++ b/package.json @@ -59,5 +59,6 @@ "modulePathIgnorePatterns": [ "/lib/" ] - } -} + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" +} \ No newline at end of file diff --git a/src/toggle.tsx b/src/toggle.tsx index 62156fb..bc0dfa0 100644 --- a/src/toggle.tsx +++ b/src/toggle.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState } from "react"; +import React from "react"; import { Animated, StyleSheet, @@ -10,7 +10,6 @@ import { COLOR_DEFAULT, DefaultReactNativeToggleElementProps, DefaultThumbChildrenProps, - SIZE_DEFAULT, ToggleStyles, ToggleThumbButtonStyles, ToogleTrackBarStyles, @@ -18,8 +17,7 @@ import { import { useTitleTextColor, useToggleValue } from "./hooks"; import { ReactNativeToggleElementProps, ThumbChildrenProps } from "./types"; -const ThumbChildren = (props: ThumbChildrenProps) => { - const { +const ThumbChildren = ({ toggleValue, activeColor, inActiveColor, @@ -28,7 +26,7 @@ const ThumbChildren = (props: ThumbChildrenProps) => { children, disabled, disabledTitleStyle, - } = props; + }: ThumbChildrenProps = DefaultThumbChildrenProps) => { if (children) { return {children}; @@ -58,10 +56,7 @@ const ThumbChildren = (props: ThumbChildrenProps) => { return null; }; -ThumbChildren.defaultProps = DefaultThumbChildrenProps; - -const ReactNativeToggleElement = (props: ReactNativeToggleElementProps) => { - const { +const ReactNativeToggleElement = ({ value, leftComponent, rightComponent, @@ -79,8 +74,7 @@ const ReactNativeToggleElement = (props: ReactNativeToggleElementProps) => { rightTitle, animationDuration, onPress, - } = props; - + }: ReactNativeToggleElementProps = DefaultReactNativeToggleElementProps) => { const { toggleValue, handlePress, handleLongPress, fadeAnim } = useToggleValue(value, thumbButton, trackBar, animationDuration, onPress); @@ -90,7 +84,7 @@ const ReactNativeToggleElement = (props: ReactNativeToggleElementProps) => { inActiveBackgroundColor, borderInActiveColor, borderActiveColor, - } = props.trackBar; + } = trackBar; activeBackgroundColor = activeBackgroundColor ?? COLOR_DEFAULT.trackActiveBg; @@ -153,8 +147,8 @@ const ReactNativeToggleElement = (props: ReactNativeToggleElementProps) => { > { > { ); }; -ReactNativeToggleElement.defaultProps = DefaultReactNativeToggleElementProps; - export default ReactNativeToggleElement; From 3728d751231951bb99ea3d5398f7d27335549f1d Mon Sep 17 00:00:00 2001 From: Nathanael Martins <49047480+natemartins@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:15:43 +0100 Subject: [PATCH 2/2] refactor: update main module field --- package.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/package.json b/package.json index 60de668..b1eeb0d 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,12 @@ "name": "react-native-toggle-element", "version": "2.0.1", "description": "Switch toggle component for React Native. You can add title, icon, modify component for toggle button.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "./src/index.ts", "scripts": { "build": "tsc --project ./tsconfig.json", "test": "jest", "lint": "tslint --project ./tsconfig.json" }, - "files": [ - "lib/**/*" - ], "repository": { "type": "git", "url": "git+https://github.com/mymai91/react-native-toggle-element.git"