Skip to content

Commit

Permalink
Fix left and right top bar buttons with component crash on Android (#…
Browse files Browse the repository at this point in the history
…7253)

* Replace incorrect title bar react button view height measure spec

* Fix right button with component incorrect ID while measuring its size

* Add missing View import

* Update TitleBarReactButtonView.java

Co-authored-by: Ward Abbass <warda@wix.com>
Co-authored-by: Ward Abbass <swabbass@gmail.com>
  • Loading branch information
3 people authored Sep 14, 2021
1 parent 7351d0d commit 0f61d3f
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;

import com.facebook.react.ReactInstanceManager;
import com.reactnativenavigation.options.ComponentOptions;
Expand All @@ -24,7 +25,14 @@ public TitleBarReactButtonView(Context context, ReactInstanceManager reactInstan

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(createSpec(widthMeasureSpec, component.width), createSpec(widthMeasureSpec, component.height));

//This is a workaround, ReactNative throws exception when views have ids, On android MenuItems
// With ActionViews like this got an id, see #7253
if (!this.isAttachedToWindow() || this.getReactInstanceManager() == null) {
this.setId(View.NO_ID);
}

super.onMeasure(createSpec(widthMeasureSpec, component.width), createSpec(heightMeasureSpec, component.height));
}

private int createSpec(int measureSpec, Number dimension) {
Expand Down

0 comments on commit 0f61d3f

Please sign in to comment.