Skip to content

Commit 0f61d3f

Browse files
svbutkoswabbass
andauthored
Fix left and right top bar buttons with component crash on Android (#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>
1 parent 7351d0d commit 0f61d3f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/android/app/src/main/java/com/reactnativenavigation/views/stack/topbar/titlebar/TitleBarReactButtonView.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.annotation.SuppressLint;
44
import android.content.Context;
5+
import android.view.View;
56

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

2526
@Override
2627
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
27-
super.onMeasure(createSpec(widthMeasureSpec, component.width), createSpec(widthMeasureSpec, component.height));
28+
29+
//This is a workaround, ReactNative throws exception when views have ids, On android MenuItems
30+
// With ActionViews like this got an id, see #7253
31+
if (!this.isAttachedToWindow() || this.getReactInstanceManager() == null) {
32+
this.setId(View.NO_ID);
33+
}
34+
35+
super.onMeasure(createSpec(widthMeasureSpec, component.width), createSpec(heightMeasureSpec, component.height));
2836
}
2937

3038
private int createSpec(int measureSpec, Number dimension) {

0 commit comments

Comments
 (0)