react-native-toggle-element
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "react-native-toggle-element", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Switch toggle component for React Native. You can add title, icon, modify component for toggle button.", | ||
@@ -39,2 +39,2 @@ "main": "src/index.js", | ||
} | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
# React-Native-Toggle-Element | ||
# React-Native-Toggle-Element [](https://circleci.com/gh/mymai91/react-native-toggle-element) | ||
 | ||
 | ||
 | ||
@@ -121,3 +121,3 @@ ## Installation | ||
 | ||
 | ||
@@ -124,0 +124,0 @@ ```jsx |
@@ -376,3 +376,3 @@ import * as React from 'react'; | ||
expect(setToggleValue).toHaveBeenCalledTimes(1); | ||
expect(setToggleValue).toHaveBeenCalledTimes(2); | ||
@@ -403,3 +403,3 @@ fireEvent.press(getByTestId('ToggleButton')); | ||
expect(setToggleValue).toHaveBeenCalledTimes(1); | ||
expect(setToggleValue).toHaveBeenCalledTimes(2); | ||
}); | ||
@@ -406,0 +406,0 @@ }); |
import PropTypes from 'prop-types'; | ||
import React, { useRef, useState } from 'react'; | ||
import React, { useRef, useState, useEffect } from 'react'; | ||
import { | ||
@@ -111,2 +111,3 @@ Animated, | ||
rightTitle, | ||
animationDuration | ||
} = props; | ||
@@ -116,2 +117,10 @@ | ||
useEffect(() => { | ||
updateThumbButton(toggleValue) | ||
}, [toggleValue]) | ||
useEffect(() => { | ||
setToggleValue(value); | ||
}, [value]) | ||
const updateThumbButton = (toggleState) => { | ||
@@ -125,3 +134,3 @@ const thumbBtnWidth = thumbButton.width ?? SIZE_DEFAULT.thumbBtnWidth; | ||
toValue, | ||
duration: 350, | ||
duration: animationDuration, | ||
useNativeDriver: true, | ||
@@ -136,3 +145,2 @@ }).start(); | ||
onPress(val); | ||
updateThumbButton(val); | ||
}; | ||
@@ -297,2 +305,3 @@ | ||
rightTitle: PropTypes.string, | ||
animationDuration: PropTypes.number | ||
}; | ||
@@ -336,2 +345,3 @@ | ||
thumbStyle: null, | ||
animationDuration: 350 | ||
}; | ||
@@ -391,2 +401,2 @@ | ||
export default ReactNativeToggleElement; | ||
export default ReactNativeToggleElement; |
38059
14
702