Revolver View
A revolving picker view.
Inspired by the work of Oleg Frolov — Search icon interaction II.
Installation
$ npm install react-native-revolver-view
$ yarn add react-native-revolver-view
Additional dependencies:
$ npm install react-native-reanimated react-native-gesture-handler @react-native-community/masked-view react-native-svg
$ yarn add react-native-reanimated react-native-gesture-handler @react-native-community/masked-view react-native-svg
RN < 0.60 users need to perform linking.
iOS step only:
$ npx pod-install ios
Finalize the installation of react-native-gesture-handler
by adding the following to the top of index.js
(must be at the top):
import 'react-native-gesture-handler'
Usage
import RevolverView, { SearchIcon } from "react-native-revolver-view"
const items = ["All", "Videos", "Images", "News"]
const App = () => {
const [activeIndex, setActiveIndex] = useState(0)
const handleNewIndex = newIndex => setActiveIndex(newIndex)
return (
<View
style={{
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#FFCA27",
}}>
<RevolverView
items={items}
activeIndex={activeIndex}
onChangeIndex={handleNewIndex}
rotatingComponent={<SearchIcon iconColor="#DDD9CB" />}
containerStyle={{
width: "50%",
}}
/>
<View style={{ marginTop: 50 }} />
<Button title="Set to index 2" onPress={() => handleNewIndex(2)} />
</View>
)
}
For more advanced usage, check out this example.
Props
Item in Gif | Prop | Gif |
---|
White container | containerStyle | |
wow | rotatingComponent |
'what is going on' | items |
'Flexible' button | children |
interface RevolverViewProps {
items: string[]
activeIndex: number
onChangeIndex: (newIndex: number) => void
containerStyle?: ViewStyle
itemColor?: string
itemStyle?: TextStyle
rotatingComponent?: React.ReactElement<any>
rippleActiveOpacity?: number
rippleColor?: string
children?: ReactChild
}
interface SearchIconProps {
iconColor: string
iconSize?: number
}
License
MIT