/* @flow */ import React, { Component } from 'react' import { StyleSheet, Text, View, } from 'react-native' import SegmentedControlTab from 'react-native-segmented-control-tab' class SegmentedView extends Component<*, *> { constructor() { super() this.state = { selectedIndex: 0, selectedIndices: [0], customStyleIndex: 0, } } handleSingleIndexSelect = (index: number) => { this.setState(prevState => ({ ...prevState, selectedIndex: index })) } handleMultipleIndexSelect = (index: number) => { const { selectedIndices } = this.state if (selectedIndices.includes(index)) { this.setState(prevState => ({ ...prevState, selectedIndices: selectedIndices.filter((i) => i !== index), })) } else { this.setState(prevState => ({ ...prevState, selectedIndices: [ ...selectedIndices, index, ], })) } } handleCustomIndexSelect = (index: number) => { this.setState(prevState => ({ ...prevState, customStyleIndex: index })) } render() { const { selectedIndex, selectedIndices, customStyleIndex } = this.state return ( Default segmented control with single selection Default segmented control with multiple selection Default segmented with badges Custom segmented control with custom styles {customStyleIndex === 0 && Tab one} {customStyleIndex === 1 && Tab two} ) } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'white', padding: 10, }, tabViewText: { color: '#444444', fontWeight: 'bold', marginTop: 50, fontSize: 18, }, titleText: { color: '#444444', padding: 20, fontSize: 14, fontWeight: '500', }, headerText: { padding: 8, fontSize: 14, color: '#444444', }, tabContent: { color: '#444444', fontSize: 18, margin: 24, }, Seperator: { marginHorizontal: -10, alignSelf: 'stretch', borderTopWidth: 1, borderTopColor: '#888888', marginTop: 24, }, tabStyle: { borderColor: '#D52C43', }, activeTabStyle: { backgroundColor: '#D52C43', }, tabTextStyle: { color: '#D52C43', }, }) export default SegmentedView