Skip to content

Commit

Permalink
Make it runnable on 0.34+
Browse files Browse the repository at this point in the history
  • Loading branch information
sooth-sayer committed Oct 28, 2016
1 parent e633ee6 commit e629b9f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
22 changes: 13 additions & 9 deletions AndroidSegmented.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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 (
<NativeAndroidSegmented
{...this.props}
{...this.props}
onChange={this._onChange}/>
);
}
Expand All @@ -47,8 +53,6 @@ AndroidSegmented.propTypes = {
onChange: PropTypes.func,
}

AndroidSegmented.defaultProps = {

};
var NativeAndroidSegmented = requireNativeComponent('AndroidSegmented', AndroidSegmented, { nativeOnly: { onChange: true } });

module.exports = AndroidSegmented;
module.exports = AndroidSegmented;
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class AndroidSegmentedEvent extends Event<AndroidSegmentedEvent> {
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;
}

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
});


}


Expand All @@ -75,8 +68,6 @@ public void setChildText(AndroidSegmented view, ReadableArray data) {

child.setText(data.getString(i));
view.addView(child);


}
}

Expand Down

0 comments on commit e629b9f

Please sign in to comment.