Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for SegmentedControlIOS component,onChange(event),event.nativeEvent =null #1310

Closed
donghanji opened this issue May 16, 2015 · 4 comments
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@donghanji
Copy link

for SegmentedControlIOS component,when used onChange event,the callback param event,event.nativeEvent is null,no selectedIndex attribute.

var EventSegmentedControlExample=React.createClass({
  getInitialState(){
    return {
      values:['One','Two','Three'],
      value:'Not selected',
      selectedIndex:undefined
    };
  },
  render(){
    return(
      <View>
        <Text style={styles.text}>
          Value:{this.state.value}
        </Text>
        <Text style={styles.text}>
          Index:{this.state.selectedIndex}
        </Text>
        <SegmentedControlIOS
          values={this.state.values}
          selectedIndex={this.state.selectedIndex}
          onChange={this._onChange}
          onValueChange={this._onValueChange}
        />
      </View>
    );
  },
_onChange(event){
    console.log(event);//debug console log here
    this.setState({
      selectedIndex:event.nativeEvent.selectedIndex
    });
  },
  _onValueChange(value){
    this.setState({
      value:value
    });
  }
});

//render EventSegmentedControlExample
//

this is console log:

_dispatchIDs: null,
_dispatchListeners: null,
bubbles: nullcancelable: null,
currentTarget: null,
defaultPrevented: null,
dispatchConfig: null,
dispatchMarker: null,
eventPhase: null,
isDefaultPrevented: function () {},
isPropagationStopped: function () {},
isTrusted: null,
nativeEvent: null,//there is null
target: null,
timeStamp: null,
type: null

the SegmentedControlIOS is a new component,is this an bug?

@wwxiaofeng
Copy link

use event.nativeEvent.selectedSegmentIndex

@christopherdro
Copy link
Contributor

@donghanji Did this resolve your issue?

@brentvatne
Copy link
Collaborator

@yangxf's answer is correct

@donghanji
Copy link
Author

thanks everyone ^_^.sorry to being late.
change the code ,like this:

var EventSegmentedControlExample=React.createClass({
  getInitialState(){
    return {
      values:['One','Two','Three'],
      value:'Not selected',
      selectedIndex:undefined
    };
  },
  render(){
    return(
      <View>
        <Text style={styles.text}>
          Value:{this.state.value}
        </Text>
        <Text style={styles.text}>
          Index:{this.state.selectedIndex}
        </Text>
        <SegmentedControlIOS
          values={this.state.values}
          selectedIndex={this.state.selectedIndex}
          onChange={this._onChange}
          onValueChange={this._onValueChange}
        />
      </View>
    );
  },
_onChange(event){
    console.log(event.nativeEvent);//debug console log here
    this.setState({
      selectedIndex:event.nativeEvent.selectedSegmentIndex
    });
  },
  _onValueChange(value){
    this.setState({
      value:value
    });
  }
});
//

after changed ,it work well.

Whether those changes should be updated,http://facebook.github.io/react-native/docs/segmentedcontrolios.html#content

thanks everyone again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants