Skip to content

Commit

Permalink
lint native
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Oct 3, 2024
1 parent 753bb43 commit 841b0ef
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package expo.modules.bottomsheet

import android.graphics.Color
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition

Expand Down Expand Up @@ -30,14 +29,6 @@ class BottomSheetModule : Module() {
view.updateLayout()
}

Prop("containerBackgroundColor") { view: BottomSheetView, prop: String ->
// view.sheetState.value.containerBackgroundColor = Color.parseColor(prop)
}

Prop("cornerRadius") { view: BottomSheetView, prop: Float ->
// view.sheetState.value.cornerRadius = prop
}

Prop("minHeight") { view: BottomSheetView, prop: Float ->
view.minHeight = prop
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class BottomSheetView(
context: Context,
appContext: AppContext,
) : ExpoView(context, appContext) {

private var reactRootView: ReactRootView? = null
private var innerView: View? = null
private var dialog: BottomSheetDialog? = null

private val screenHeight = context.resources.displayMetrics.heightPixels.toFloat()
private val screenHeight =
context.resources.displayMetrics.heightPixels
.toFloat()

private val onAttemptDismiss by EventDispatcher()
private val onSnapPointChange by EventDispatcher()
Expand All @@ -35,21 +36,23 @@ class BottomSheetView(
var preventExpansion = false

var minHeight = 0f
set (value) {
field = if (value < 0) {
0f
} else {
value
}
set(value) {
field =
if (value < 0) {
0f
} else {
value
}
}

var maxHeight = this.screenHeight
set (value) {
field = if (value > this.screenHeight) {
this.screenHeight.toFloat()
} else {
value
}
set(value) {
field =
if (value > this.screenHeight) {
this.screenHeight.toFloat()
} else {
value
}
}

private var isOpen: Boolean = false
Expand All @@ -66,19 +69,23 @@ class BottomSheetView(
set(value) {
field = value
if (value) {
onStateChange(mapOf(
"state" to "opening"
))
onStateChange(
mapOf(
"state" to "opening",
),
)
}
}

private var isClosing: Boolean = false
set(value) {
field = value
if (value) {
onStateChange(mapOf(
"state" to "closing"
))
onStateChange(
mapOf(
"state" to "closing",
),
)
}
}

Expand Down Expand Up @@ -164,26 +171,34 @@ class BottomSheetView(
behavior.isDraggable = true
behavior.isHideable = true

behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
when (newState) {
BottomSheetBehavior.STATE_EXPANDED -> {
selectedSnapPoint = 2
}
BottomSheetBehavior.STATE_COLLAPSED -> {
selectedSnapPoint = 1
}
BottomSheetBehavior.STATE_HALF_EXPANDED -> {
selectedSnapPoint = 1
}
BottomSheetBehavior.STATE_HIDDEN -> {
selectedSnapPoint = 0
behavior.addBottomSheetCallback(
object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(
bottomSheet: View,
newState: Int,
) {
when (newState) {
BottomSheetBehavior.STATE_EXPANDED -> {
selectedSnapPoint = 2
}
BottomSheetBehavior.STATE_COLLAPSED -> {
selectedSnapPoint = 1
}
BottomSheetBehavior.STATE_HALF_EXPANDED -> {
selectedSnapPoint = 1
}
BottomSheetBehavior.STATE_HIDDEN -> {
selectedSnapPoint = 0
}
}
}
}

override fun onSlide(bottomSheet: View, slideOffset: Float) { }
})
override fun onSlide(
bottomSheet: View,
slideOffset: Float,
) { }
},
)
}
}
dialog.setOnDismissListener {
Expand Down Expand Up @@ -232,13 +247,14 @@ class BottomSheetView(

private fun getTargetHeight(): Float {
val contentHeight = this.getContentHeight()
val height = if (contentHeight > maxHeight) {
maxHeight
} else if (contentHeight < minHeight) {
minHeight
} else {
contentHeight
}
val height =
if (contentHeight > maxHeight) {
maxHeight
} else if (contentHeight < minHeight) {
minHeight
} else {
contentHeight
}
return height
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ class SheetManager {
}
}
}
}
}
2 changes: 1 addition & 1 deletion modules/bottom-sheet/ios/BottomSheetModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BottomSheetModule: Module {
Events([
"onAttemptDismiss",
"onSnapPointChange",
"onStateChange",
"onStateChange"
])

AsyncFunction("dismiss") { (view: SheetView) in
Expand Down
2 changes: 1 addition & 1 deletion modules/bottom-sheet/ios/SheetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SheetViewController: UIViewController {
.medium()
]
}

if !preventExpansion {
sheet.detents.append(.large())
}
Expand Down

0 comments on commit 841b0ef

Please sign in to comment.