fix checkbox casting crash in old android versions (#23281)

Summary:
fixes casting on older android versions reported in #22885

[Android] [Fixed] - fix casting crash in android checkbox
Pull Request resolved: https://github.com/facebook/react-native/pull/23281

Differential Revision: D13941776

Pulled By: cpojer

fbshipit-source-id: ff3695f64d3399790a03b02d5b1363cacc655336
This commit is contained in:
Vojtech Novak
2019-02-04 07:46:49 -08:00
committed by Facebook Github Bot
parent 9ccde378b6
commit 58437cd10a

View File

@@ -6,6 +6,8 @@
*/
package com.facebook.react.views.checkbox;
import android.content.Context;
import android.support.v7.widget.TintContextWrapper;
import android.widget.CompoundButton;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.SimpleViewManager;
@@ -13,7 +15,6 @@ import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher;
/** View manager for {@link ReactCheckBox} components. */
public class ReactCheckBoxManager extends SimpleViewManager<ReactCheckBox> {
@@ -24,11 +25,22 @@ public class ReactCheckBoxManager extends SimpleViewManager<ReactCheckBox> {
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
ReactContext reactContext = (ReactContext) buttonView.getContext();
ReactContext reactContext = getReactContext(buttonView);
reactContext
.getNativeModule(UIManagerModule.class).getEventDispatcher()
.dispatchEvent(new ReactCheckBoxEvent(buttonView.getId(), isChecked));
}
private ReactContext getReactContext(CompoundButton buttonView) {
ReactContext reactContext;
Context ctx = buttonView.getContext();
if (ctx instanceof TintContextWrapper) {
reactContext = (ReactContext) ((TintContextWrapper) ctx).getBaseContext();
} else {
reactContext = (ReactContext) buttonView.getContext();
}
return reactContext;
}
};
@Override