Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

reactjs - Segmented Controls React Native

Im using the following library:

https://github.com/react-native-segmented-control/segmented-control

Iv followed the instructions to install it and everything is displaying fine, but I can't get the value to change or keep state to record the value:

    const [gender, setGender] = useState(0)


    <View style={styles.segmentContainer}>
        <SegmentedControl
            values={['Male', 'Female']}
            style={{height: 40}}
            fontStyle={styles.fontStyle}
            selectedIndex={gender}
            onChange={(event) => {
                setGender({selectedIndex: event.nativeEvent.selectedSegmentIndex});
            }}
        />
    </View>

I have imported:

import { event } from 'react-native-reanimated';

Every time I click on the other option the app crashes with the following:

Invariant Violation: [18,472,{"type":"frames","frames":[0,0.10802469135802473,0.2098765432098766,0.30555555555555547,0.3950617283950617,0.4783950617283951,0.5555555555555555,0.6265432098765431,0.691358024691358,0.75,0.8024691358024691,0.8487654320987654,0.8888888888888888,0.9228395061728395,0.9506172839506173,0.9722222222222222,0.9876543209876543,0.9969135802469136,1],"toValue":"<<NaN>>","iterations":1},10261] is not usable as a native method argument

This error is located at:
    in RootErrorBoundary (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:45)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)
question from:https://stackoverflow.com/questions/65917826/segmented-controls-react-native

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...