react-native-multiswitch-controller
Version:
Smooth animated multiswitch component with dynamic width
32 lines • 1.53 kB
TypeScript
import { type RefObject, type Ref } from 'react';
import { FlatList, type LayoutChangeEvent } from 'react-native';
import { type SharedValue, type StyleProps, useAnimatedScrollHandler } from 'react-native-reanimated';
import type { ControlOption } from './types';
export type ControlListProps<TValue> = {
options: ControlOption<TValue>[];
optionPadding: number;
optionGap: number;
defaultOption: TValue;
onPressCallback?: (value: TValue) => void;
};
export type ControlListRef<TValue> = {
setForcedOption: (value: TValue | null) => void;
activeOption: TValue;
};
export type ControlListState<TValue> = {
options: ControlOption<TValue>[];
activeOption: TValue;
animatedActiveOptionIndex: SharedValue<number | null>;
animatedActiveOptionStyle: StyleProps;
scrollHandler: ReturnType<typeof useAnimatedScrollHandler>;
controlListRef: RefObject<FlatList<ControlOption<TValue>> | null>;
onLayoutOptionItem: (event: LayoutChangeEvent, index: number) => void;
onAnimationFinish: (newValue: TValue, initialAnimationCallback?: () => void) => void;
};
/**
* Helps with animation of SegmentedControl and Tabs.
* To avoid fps drops while animating, SegmentedControl/Tabs needs to be animated first, and after that the content may be refreshed.
* */
declare function useControlListState<TValue>(props: ControlListProps<TValue>, ref?: Ref<ControlListRef<TValue>>): ControlListState<TValue>;
export default useControlListState;
//# sourceMappingURL=useControlListState.d.ts.map