|
@@ -63,10 +63,21 @@ import androidx.annotation.Nullable;
|
63
|
63
|
return windowInsets;
|
64
|
64
|
}
|
65
|
65
|
|
66
|
|
- static com.th3rdwave.safeareacontext.Rect getFrame(ViewGroup rootView, View view) {
|
|
66
|
+ static @Nullable com.th3rdwave.safeareacontext.Rect getFrame(ViewGroup rootView, View view) {
|
|
67
|
+ // This can happen while the view gets unmounted.
|
|
68
|
+ if (view.getParent() == null) {
|
|
69
|
+ return null;
|
|
70
|
+ }
|
67
|
71
|
Rect offset = new Rect();
|
68
|
72
|
view.getDrawingRect(offset);
|
69
|
|
- rootView.offsetDescendantRectToMyCoords(view, offset);
|
|
73
|
+ try {
|
|
74
|
+ rootView.offsetDescendantRectToMyCoords(view, offset);
|
|
75
|
+ } catch (IllegalArgumentException ex) {
|
|
76
|
+ // This can throw if the view is not a descendant of rootView. This should not
|
|
77
|
+ // happen but avoid potential crashes.
|
|
78
|
+ ex.printStackTrace();
|
|
79
|
+ return null;
|
|
80
|
+ }
|
70
|
81
|
|
71
|
82
|
return new com.th3rdwave.safeareacontext.Rect(offset.left, offset.top, view.getWidth(), view.getHeight());
|
72
|
83
|
}
|