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

Make it runnable on 0.34+ #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'info.hoang8f:android-segmented:1.0.6'
compile 'com.facebook.react:react-native:0.19.+'
compile 'com.facebook.react:react-native:+'
}
//react-native run-android
//adb reverse tcp:8081 tcp:8081
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-segmented-android",
"version": "1.0.4",
"version": "1.1.0",
"description": "a high imitation of iOS segmented Controls",
"main": "AndroidSegmented.js",
"scripts": {
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactApplica
new AndroidSegmentedManager());
}

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
Expand Down