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

Fixed to work under new versions React Native (tested on 0.38) #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 1 addition & 4 deletions index.android.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, PropTypes } from 'react';
import React, { Component, PropTypes } from 'react';
import { requireNativeComponent, View} from 'react-native';

var REF_PICKER = 'numberpicker';
Expand Down Expand Up @@ -28,9 +28,6 @@ class NumberPicker extends Component {
if (this.props.onSelect)
this.props.onSelect(event.nativeEvent.value);

if (this.refs[REF_PICKER] && this.state.selectedIndex !== event.nativeEvent.value)
this.refs[REF_PICKER].setNativeProps({selected: this.state.selectedIndex});

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to set the default value, does it not work in later versions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It forces the client to update the selectedIndex prop every time an "onSelect" event is received, which, while logical, may not be immediately apparent (adding it to the README would fix that).

But the bigger problem when I was testing was that setting the selectedIndex prop on the element couldn't keep up with the native events that kept resetting the picker to it's original value thanks to these two lines. The whole thing then became unusable. I'm open to any ideas on how to fix that.


render() {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "react-native-numberpicker",
"version": "0.0.4",
"version": "0.0.5",
"description": "React Native Android NumberPicker",
"repository": {
"type": "git",
"url": "https://github.com/fixd/react-native-numberpicker.git"
"url": "https://github.com/Symphony9/react-native-numberpicker"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to undo this and the author change

},
"author": "Fixd",
"author": "DanielMaly",
"license": "MIT"
}
33 changes: 0 additions & 33 deletions src/main/java/io/fixd/numberpicker/RNNumberPickerChangeEvent.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import javax.annotation.Nullable;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
Expand All @@ -11,22 +14,27 @@
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.uimanager.UIProp;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.events.RCTEventEmitter;

import java.lang.Integer;
import java.lang.String;

public class RNNumberPickerManager extends SimpleViewManager<RNNumberPicker> {
public class RNNumberPickerManager extends SimpleViewManager<RNNumberPicker>
implements RNNumberPicker.OnChangeListener {

public static final String REACT_CLASS = "RNNumberPicker";

private RNNumberPicker view;

@Override
public String getName() {
return REACT_CLASS;
}

@Override
protected RNNumberPicker createViewInstance(ThemedReactContext reactContext) {
return new RNNumberPicker(reactContext);
this.view = new RNNumberPicker(reactContext);
return this.view;
}

@ReactProp(name = "values")
Expand All @@ -48,30 +56,17 @@ public void setValue(RNNumberPicker view, Integer selected) {

@Override
protected void addEventEmitters(final ThemedReactContext reactContext, final RNNumberPicker picker) {
picker.setOnChangeListener(
new RNNumberPickerEventEmitter(
picker,
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()
)
);
picker.setOnChangeListener(this);
}

private static class RNNumberPickerEventEmitter implements RNNumberPicker.OnChangeListener {

private final RNNumberPicker mRNNumberPicker;
private final EventDispatcher mEventDispatcher;

public RNNumberPickerEventEmitter(RNNumberPicker reactNumberPicker, EventDispatcher eventDispatcher) {
mRNNumberPicker = reactNumberPicker;
mEventDispatcher = eventDispatcher;
}

@Override
public void onValueChange(int value) {
mEventDispatcher.dispatchEvent(
new RNNumberPickerChangeEvent(mRNNumberPicker.getId(), SystemClock.nanoTime(), value)
);
}
@Override
public void onValueChange(int value) {
WritableMap event = Arguments.createMap();
event.putInt("value", value);
ReactContext reactContext = (ReactContext) view.getContext();
reactContext.getJSModule(RCTEventEmitter.class)
.receiveEvent(view.getId(), "topChange", event);
}


}