Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const useToggleValue = (
thumbButton: ThumbButton,
trackBar: TrackBar,
animationDuration: number,
onPress: (val?: boolean) => void
onPress: (val?: boolean) => void,
managed: boolean
) => {
const fadeAnim = useRef(new Animated.Value(0)).current;

Expand Down Expand Up @@ -53,7 +54,9 @@ export const useToggleValue = (

const handleToggle = () => {
const val = !toggleValue;
setToggleValue(val);
if(!managed) {
setToggleValue(val);
}
onPress(val);
};

Expand Down
8 changes: 7 additions & 1 deletion src/toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const ReactNativeToggleElement = (props: ReactNativeToggleElementProps) => {
leftTitle = "",
rightTitle = "",
animationDuration = 250,
activeTrackBarComponent,
inActiveTrackBarComponent,
managed = false
} = { ...DefaultThumbChildrenProps, ...props };

const finalTrackBar = { ...defaultTrackBar, ...customTrackBar };
Expand All @@ -87,7 +90,8 @@ const ReactNativeToggleElement = (props: ReactNativeToggleElementProps) => {
finalThumbButton,
finalTrackBar,
animationDuration,
onPress
onPress,
managed,
);

const trackBarBackgroundColor = () => {
Expand Down Expand Up @@ -128,6 +132,8 @@ const ReactNativeToggleElement = (props: ReactNativeToggleElementProps) => {
disabled && disabledStyle,
])}
>
{toggleValue && activeTrackBarComponent}
{!toggleValue && inActiveTrackBarComponent}
<View
testID="ThumbButtonLeft"
style={StyleSheet.flatten([
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export interface ReactNativeToggleElementProps {
leftTitle?: string | null;
rightTitle?: string | null;
animationDuration?: number;
activeTrackBarComponent?: React.ReactNode;
inActiveTrackBarComponent?: React.ReactNode;
managed: boolean;
}
export interface Styles {
container: ViewStyle;
Expand Down