Skip to content

Commit

Permalink
fix checkbox casting crash in old android versions (#23281)
Browse files Browse the repository at this point in the history
Summary:
fixes casting on older android versions reported in #22885

[Android] [Fixed] - fix casting crash in android checkbox
Pull Request resolved: #23281

Differential Revision: D13941776

Pulled By: cpojer

fbshipit-source-id: ff3695f64d3399790a03b02d5b1363cacc655336
  • Loading branch information
vonovak authored and facebook-github-bot committed Feb 4, 2019
1 parent 9ccde37 commit 58437cd
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
*/
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;
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> {
Expand All @@ -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
Expand Down

1 comment on commit 58437cd

@javadi69
Copy link

@javadi69 javadi69 commented on 58437cd May 5, 2019

Choose a reason for hiding this comment

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

I have made these changes but looks like my application uses another .jar file.
My React-Native version is 0.58.6

java.lang.ClassCastException: android.support.v7.widget.TintContextWrapper cannot be cast to com.facebook.react.bridge.ReactContext at com.facebook.react.views.checkbox.ReactCheckBoxManager$1.onCheckedChanged(ReactCheckBoxManager.java:27) at android.widget.CompoundButton.setChecked(CompoundButton.java:126) at com.facebook.react.views.checkbox.ReactCheckBox.setChecked(ReactCheckBox.java:26) at android.widget.CompoundButton.toggle(CompoundButton.java:87) at android.widget.CompoundButton.performClick(CompoundButton.java:99) at android.view.View$PerformClick.run(View.java:17721) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5103) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)

ReactCheckBoxManager.java:27 references to below address:
node_modules\react-native\android\com\facebook\react\react-native\0.58.6\react-native-0.58.6-sources.jar

Can anybody please help me on that?

Please sign in to comment.