Skip to content

Commit 3644f6b

Browse files
authored
fix(Android, FormSheet): Add fallback for undefined corner radius (#3291)
## Description While working on a different task, I noticed that on Android API level 28 or below, the FormSheet might not display correctly. The issue was caused by passing a negative corner radius value when it was `undefined` on the JS side, which `ShapeAppearanceModel` could not handle properly. This PR adds a fallback to 0 when the value is not provided. Fixes software-mansion/react-native-screens-labs#480 ## Changes - Added a fallback for `sheetCornerRadius` prop ## Screenshots / GIFs ### Before <img width="430" height="848" alt="Screenshot 2025-10-10 at 14 57 47" src="https://github.com/user-attachments/assets/3dfa849d-d574-4d15-985e-a8e83615e099" /> ### After <img width="433" height="844" alt="Screenshot 2025-10-10 at 14 58 10" src="https://github.com/user-attachments/assets/24fdaaa8-4a1a-4d61-a2e6-c65fd1799f91" /> ## Test code and steps to reproduce You can open `GlossyFormSheet` from `TestFormSheet` on Android 28 or lower; I haven't defined `sheetCornerRadius` there. ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes
1 parent c11e153 commit 3644f6b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

android/src/main/java/com/swmansion/rnscreens/Screen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import com.swmansion.rnscreens.events.SheetDetentChangedEvent
3434
import com.swmansion.rnscreens.ext.asScreenStackFragment
3535
import com.swmansion.rnscreens.ext.parentAsViewGroup
3636
import com.swmansion.rnscreens.gamma.common.FragmentProviding
37+
import kotlin.math.max
3738

3839
@SuppressLint("ViewConstructor") // Only we construct this view, it is never inflated.
3940
class Screen(
@@ -518,7 +519,7 @@ class Screen(
518519
return
519520
}
520521
(background as? MaterialShapeDrawable?)?.let {
521-
val resolvedCornerRadius = PixelUtil.toDIPFromPixel(sheetCornerRadius)
522+
val resolvedCornerRadius = max(PixelUtil.toDIPFromPixel(sheetCornerRadius), 0f)
522523
it.shapeAppearanceModel =
523524
ShapeAppearanceModel
524525
.Builder()

android/src/main/java/com/swmansion/rnscreens/ScreenStackFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.swmansion.rnscreens.stack.views.ScreensCoordinatorLayout
3939
import com.swmansion.rnscreens.transition.ExternalBoundaryValuesEvaluator
4040
import com.swmansion.rnscreens.utils.DeviceUtils
4141
import com.swmansion.rnscreens.utils.resolveBackgroundColor
42+
import kotlin.math.max
4243

4344
sealed class KeyboardState
4445

@@ -367,7 +368,7 @@ class ScreenStackFragment :
367368
}
368369

369370
private fun attachShapeToScreen(screen: Screen) {
370-
val cornerSize = PixelUtil.toPixelFromDIP(screen.sheetCornerRadius)
371+
val cornerSize = max(PixelUtil.toPixelFromDIP(screen.sheetCornerRadius), 0f)
371372
val shapeAppearanceModel =
372373
ShapeAppearanceModel
373374
.Builder()

0 commit comments

Comments
 (0)