Skip to content

Commit b5050ac

Browse files
committed
fix: bugfixes
1 parent 267e21a commit b5050ac

File tree

3 files changed

+52
-43
lines changed

3 files changed

+52
-43
lines changed
Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,54 @@
11
package com.sampleapp
22

3-
import com.facebook.react.ReactActivity
4-
import com.facebook.react.ReactActivityDelegate
5-
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
6-
import com.facebook.react.defaults.DefaultReactActivityDelegate
7-
8-
import android.os.Bundle
93
import android.os.Build
4+
import android.os.Bundle
105
import android.view.View
6+
import androidx.core.graphics.Insets
117
import androidx.core.view.ViewCompat
128
import androidx.core.view.WindowInsetsCompat
139
import androidx.core.view.updatePadding
10+
import com.facebook.react.ReactActivity
11+
import com.facebook.react.ReactActivityDelegate
12+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
13+
import com.facebook.react.defaults.DefaultReactActivityDelegate
1414

1515
class MainActivity : ReactActivity() {
1616

17-
override fun onCreate(savedInstanceState: Bundle?) {
18-
super.onCreate(null)
19-
20-
if (Build.VERSION.SDK_INT >= 35) {
21-
val rootView = findViewById<View>(android.R.id.content)
22-
23-
24-
ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, insets ->
25-
val bars = insets.getInsets(
26-
WindowInsetsCompat.Type.systemBars()
27-
or WindowInsetsCompat.Type.displayCutout()
28-
or WindowInsetsCompat.Type.ime() // adding the ime's height
29-
)
30-
rootView.updatePadding(
31-
left = bars.left,
32-
top = bars.top,
33-
right = bars.right,
34-
bottom = bars.bottom
35-
)
36-
WindowInsetsCompat.CONSUMED
37-
}
38-
}
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
super.onCreate(null)
19+
20+
if (Build.VERSION.SDK_INT >= 35) {
21+
val rootView = findViewById<View>(android.R.id.content)
22+
23+
// Keep the original padding so we can restore it when IME closes
24+
val initial = Insets.of(
25+
rootView.paddingLeft,
26+
rootView.paddingTop,
27+
rootView.paddingRight,
28+
rootView.paddingBottom
29+
)
30+
31+
ViewCompat.setOnApplyWindowInsetsListener(rootView) { v, insets ->
32+
// Only apply IME (keyboard) to avoid breaking safe-area libs or double-padding system bars.
33+
val ime = insets.getInsets(WindowInsetsCompat.Type.ime())
34+
35+
v.updatePadding(
36+
left = initial.left,
37+
top = initial.top,
38+
right = initial.right,
39+
bottom = initial.bottom + ime.bottom
40+
)
41+
42+
// IMPORTANT: don't consume — allow insets to propagate to RN & safe-area-context
43+
insets
3944
}
40-
/**
41-
* Returns the name of the main component registered from JavaScript. This is used to schedule
42-
* rendering of the component.
43-
*/
44-
override fun getMainComponentName(): String = "SampleApp"
45-
46-
/**
47-
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
48-
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
49-
*/
50-
override fun createReactActivityDelegate(): ReactActivityDelegate =
51-
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
45+
46+
// Make sure we get an initial insets dispatch
47+
}
48+
}
49+
50+
override fun getMainComponentName(): String = "SampleApp"
51+
52+
override fun createReactActivityDelegate(): ReactActivityDelegate =
53+
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
5254
}

package/src/components/Message/Message.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
22
import {
33
GestureResponderEvent,
44
Keyboard,
5+
StatusBar,
56
StyleProp,
67
useWindowDimensions,
78
View,
@@ -79,7 +80,9 @@ const measureInWindow = (
7980
const handle = node.current;
8081
if (!handle) return reject(new Error('No native handle'));
8182

82-
handle.measureInWindow((x, y, w, h) => resolve({ h, w, x, y }));
83+
handle.measureInWindow((x, y, w, h) =>
84+
resolve({ h, w, x, y: y + (StatusBar.currentHeight ?? 0) }),
85+
);
8386
});
8487
};
8588

package/src/contexts/overlayContext/OverlayProvider.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
BackHandler,
55
Dimensions,
66
Platform,
7+
Pressable,
78
StatusBar,
89
StyleSheet,
910
useWindowDimensions,
@@ -425,11 +426,14 @@ const OverlayHostLayer = () => {
425426
/>
426427
) : null}
427428

428-
<Animated.View style={[contentStyle]}>
429+
<Animated.View style={contentStyle}>
430+
{isActive ? (
431+
<Pressable onPress={closeOverlay} style={StyleSheet.absoluteFillObject} />
432+
) : null}
429433
<Animated.View style={[topItemStyle, topItemTranslateStyle, styles.shadow3]}>
430434
<PortalHost name='top-item' style={StyleSheet.absoluteFillObject} />
431435
</Animated.View>
432-
<Animated.View pointerEvents='box-none' style={[hostStyle, hostTranslateStyle]}>
436+
<Animated.View style={[hostStyle, hostTranslateStyle]}>
433437
<PortalHost name='message-overlay' style={StyleSheet.absoluteFillObject} />
434438
</Animated.View>
435439
<Animated.View style={[bottomItemStyle, bottomItemTranslateStyle, styles.shadow3]}>

0 commit comments

Comments
 (0)