diff --git a/AndroidSegmented.js b/AndroidSegmented.js index a7ac396..2841745 100644 --- a/AndroidSegmented.js +++ b/AndroidSegmented.js @@ -1,9 +1,15 @@ 'use strict'; -var React = require('react-native'); -var { requireNativeComponent, PropTypes, View } = React; +var React = require('react'); +var ReactNative = require('react-native'); + +var PropTypes = React.PropTypes; + +var { + requireNativeComponent, + View, +} = ReactNative; -var NativeAndroidSegmented = requireNativeComponent('AndroidSegmented', AndroidSegmented); class AndroidSegmented extends React.Component { constructor() { @@ -13,14 +19,14 @@ class AndroidSegmented extends React.Component { _onChange(event) { if (this.props.onChange) { - this.props.onChange(event.nativeEvent); + this.props.onChange(event.nativeEvent.selectedPosition); } } render() { return ( ); } @@ -47,8 +53,6 @@ AndroidSegmented.propTypes = { onChange: PropTypes.func, } -AndroidSegmented.defaultProps = { - -}; +var NativeAndroidSegmented = requireNativeComponent('AndroidSegmented', AndroidSegmented, { nativeOnly: { onChange: true } }); -module.exports = AndroidSegmented; \ No newline at end of file +module.exports = AndroidSegmented; diff --git a/src/main/java/com/higo/zhangyp/segmented/AndroidSegmentedEvent.java b/src/main/java/com/higo/zhangyp/segmented/AndroidSegmentedEvent.java index 5aa6c22..28d94c8 100644 --- a/src/main/java/com/higo/zhangyp/segmented/AndroidSegmentedEvent.java +++ b/src/main/java/com/higo/zhangyp/segmented/AndroidSegmentedEvent.java @@ -15,8 +15,8 @@ public class AndroidSegmentedEvent extends Event { public static final String EVENT_NAME = "topChange"; private final int selectedPosition; - public AndroidSegmentedEvent(int viewId, long timestampMs, int selectedPosition) { - super(viewId, timestampMs); + public AndroidSegmentedEvent(int viewId, int selectedPosition) { + super(viewId); this.selectedPosition = selectedPosition; } @@ -40,9 +40,7 @@ public short getCoalescingKey() { private WritableMap serializeEventData() { WritableMap eventData = Arguments.createMap(); -// eventData.putInt("target", getViewTag()); - eventData.putInt("selected", getPosition()); - Log.e("AAA","position="+getPosition()); + eventData.putInt("selectedPosition", getPosition()); return eventData; } diff --git a/src/main/java/com/higo/zhangyp/segmented/AndroidSegmentedManager.java b/src/main/java/com/higo/zhangyp/segmented/AndroidSegmentedManager.java index 6b1216d..484f476 100644 --- a/src/main/java/com/higo/zhangyp/segmented/AndroidSegmentedManager.java +++ b/src/main/java/com/higo/zhangyp/segmented/AndroidSegmentedManager.java @@ -48,21 +48,14 @@ public void onCheckedChanged(RadioGroup group, int checkedId) { for (int i = 0; i < childCount; i++) { ((RadioButton)view.getChildAt(i)).setChecked(false); if (view.getChildAt(i).getId() == checkedId) { - ((RadioButton)view.getChildAt(i)).setChecked(true); + ((RadioButton)view.getChildAt(i)).setChecked(true); - - reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher() - .dispatchEvent( - new AndroidSegmentedEvent( - view.getId(), - SystemClock.uptimeMillis(), - i)); + reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher() + .dispatchEvent(new AndroidSegmentedEvent(view.getId(), i)); } } } }); - - } @@ -75,8 +68,6 @@ public void setChildText(AndroidSegmented view, ReadableArray data) { child.setText(data.getString(i)); view.addView(child); - - } }