BlueWallet/components/SegmentControl.tsx

46 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-06-09 03:19:15 +02:00
import React from 'react';
import { requireNativeComponent, View, StyleSheet, NativeSyntheticEvent } from 'react-native';
interface SegmentedControlProps {
values: string[];
selectedIndex: number;
onChange: (index: number) => void;
}
interface SegmentedControlEvent {
selectedIndex: number;
}
interface NativeSegmentedControlProps {
values: string[];
selectedIndex: number;
onChangeEvent: (event: NativeSyntheticEvent<SegmentedControlEvent>) => void;
style?: object;
}
const NativeSegmentedControl = requireNativeComponent<NativeSegmentedControlProps>('CustomSegmentedControl');
const SegmentedControl: React.FC<SegmentedControlProps> = ({ values, selectedIndex, onChange }) => {
const handleChange = (event: NativeSyntheticEvent<SegmentedControlEvent>) => {
onChange(event.nativeEvent.selectedIndex);
};
return (
<View style={styles.container}>
<NativeSegmentedControl values={values} selectedIndex={selectedIndex} style={styles.segmentedControl} onChangeEvent={handleChange} />
</View>
);
};
const styles = StyleSheet.create({
container: {
width: '100%',
2024-06-12 04:53:21 +02:00
padding: 18,
2024-06-09 03:19:15 +02:00
},
segmentedControl: {
height: 40,
},
});
export default SegmentedControl;