Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README updated #26

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function App() {

- [Oliver Lopez](https://x.com/oliverloops)

## To Do (WIP)
## To Do

- [x] Button
- [x] Switch
Expand All @@ -69,10 +69,17 @@ export default function App() {
- [x] Text
- [x] Carousel
- [x] Snackbar
- [ ] Bottom Sheet
- [x] Bottom Sheet
- [x] Time/Date Picker (WIP...)
- [x] LazyColumn/Row (just add a `lazy` prop to the existing components)
- [x] LazyGrid (vertical and horizontal props from the same component)
- [x] LazyStaggeredGrid (vertical and horizontal props from the same component)
- [x] Box

- ### We're currently adding more (feel free to suggest new composables)

- [ ] DropdownMenu
- [ ] NavigationRail
- [ ] SearchBar
- [ ] LinearWavyProgressIndicator
- [ ] More modifiers!
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (useManagedAndroidSdkVersions) {
useDefaultAndroidSdkVersions()
} else {
buildscript {
ext.kotlin_version = '1.9.24'
// Simple helper that allows the root project to override versions declared by this library.
ext.safeExtGet = { prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
Expand All @@ -37,7 +38,7 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.14"
kotlinCompilerExtensionVersion = "1.5.10"
}
defaultConfig {
versionCode 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ data class BadgeProps(
class BadgeView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(BadgeProps())

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class BadgedBoxView(context: Context, appContext: AppContext) : ExpoView(context
}
}

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package expo.modules.jetpackcomposereactnative.views.bottomsheet

import expo.modules.jetpackcomposereactnative.common.ModifierProp
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition

class BottomSheetModule : Module() {
override fun definition() = ModuleDefinition {
Name("BottomSheetView")
View(BottomSheetView::class) {
Events("onDismiss")
Prop("modifier") { view: BottomSheetView, prop: ModifierProp ->
view.updateModifier(prop)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package expo.modules.jetpackcomposereactnative.views.bottomsheet

import android.content.Context
import android.view.View
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.viewinterop.AndroidView
import expo.modules.jetpackcomposereactnative.common.ModifierProp
import expo.modules.jetpackcomposereactnative.common.toModifier
import expo.modules.kotlin.AppContext
import expo.modules.kotlin.views.ExpoView
import expo.modules.kotlin.viewevent.EventDispatcher
import expo.modules.kotlin.viewevent.ViewEventCallback

data class BottomSheetProps(
var children: List<View> = emptyList(),
var modifier: ModifierProp = emptyList()
)

class BottomSheetView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(BottomSheetProps())
private val onDismiss by EventDispatcher()

override fun addView(child: View?, index: Int) {
if (child is ComposeView) {
super.addView(child, index)
} else {
if (child != null) {
props.value = props.value.copy(children = props.value.children + child)
}
}
}

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
it.setContent {
BottomSheetComposable(
props = props.value,
onDismissRequest = onDismiss
)
}
addView(it)
}
}

fun updateModifier(modifier: ModifierProp) {
props.value = props.value.copy(modifier = modifier)
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BottomSheetComposable(
props: BottomSheetProps,
onDismissRequest: ViewEventCallback<Map<String, Any>>
){
val sheetState = rememberModalBottomSheetState()
val modifier: Modifier = props.modifier.toModifier()

ModalBottomSheet(
onDismissRequest = {
onDismissRequest(mapOf())
},
sheetState = sheetState,
sheetMaxWidth = BottomSheetDefaults.SheetMaxWidth,
containerColor = BottomSheetDefaults.ContainerColor,
shape = BottomSheetDefaults.ExpandedShape,
tonalElevation = 0.dp
) {
props.children.map { child ->
AndroidView(
factory = { child },
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class BoxView(context: Context, appContext: AppContext) : ExpoView(context, appC
}
}

override val shouldUseAndroidLayout = true


init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class ButtonView(context: Context, appContext: AppContext) : ExpoView(context, a
private var props = mutableStateOf(ButtonProps())
private val onButtonClick by EventDispatcher()

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ data class CardProps(
class CardView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(CardProps())

override val shouldUseAndroidLayout = true

override fun addView(child: View?, index: Int) {
if (child is ComposeView) {
super.addView(child, index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ data class CarouselProps(
class CarouselView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(CarouselProps())

override val shouldUseAndroidLayout = true


init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class CheckboxView(context: Context, appContext: AppContext) : ExpoView(context,
private var props = mutableStateOf(CheckboxProps())
private val onCheckedChange by EventDispatcher()

override val shouldUseAndroidLayout = true


init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class ChipView(context: Context, appContext: AppContext) : ExpoView(context, app
private var props = mutableStateOf(ChipProps())
private val onChipClick by EventDispatcher()

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ data class ColumnProps(
class ColumnView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(ColumnProps())

override val shouldUseAndroidLayout = true

override fun addView(child: View?, index: Int) {
if (child is ComposeView) {
super.addView(child, index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class DialogView(context: Context, appContext: AppContext) : ExpoView(context, a
private val onConfirm by EventDispatcher()
private val onDismiss by EventDispatcher()

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class DividerView(context: Context, appContext: AppContext) : ExpoView(context,
private var props = mutableStateOf(DividerProps())
private val onDividerClick by EventDispatcher()

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ data class GridProps (
class GridView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(GridProps())

override val shouldUseAndroidLayout = true

override fun addView(child: View?, index: Int) {
if (child is ComposeView) {
super.addView(child, index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ data class IconProps(
class IconView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(IconProps())

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class ImageView(context: Context, appContext: AppContext) : ExpoView(context, ap
private var props = mutableStateOf(ImageProps())
private var composeView: ComposeView? = null

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ data class ProgressIndicatorProps(
class ProgressIndicatorView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(ProgressIndicatorProps())

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ data class RowProps(
class RowView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(RowProps())

override val shouldUseAndroidLayout = true

override fun addView(child: View?, index: Int) {
if (child is ComposeView) {
super.addView(child, index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ data class ScaffoldProps(
class ScaffoldView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(ScaffoldProps())

override val shouldUseAndroidLayout = true

override fun addView(child: View?, index: Int) {
if (child is ComposeView) {
super.addView(child, index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class SliderView(context: Context, appContext: AppContext) : ExpoView(context, a
private var props = mutableStateOf(SliderProps())
private val onValueChange by EventDispatcher()

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class SnackbarView(context: Context, appContext: AppContext) : ExpoView(context,
private val onActionPerformed by EventDispatcher()
private val onDismissed by EventDispatcher()

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class SpacerView(context: Context, appContext: AppContext) : ExpoView(context, a
private var props = mutableStateOf(SpacerProps())
private val onSpacerClick by EventDispatcher()

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class SwitchView(context: Context, appContext: AppContext) : ExpoView(context, a
private var props = mutableStateOf(SwitchProps())
private val onCheckedChange by EventDispatcher()

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class TextView(context: Context, appContext: AppContext) : ExpoView(context, app
private var props = mutableStateOf(TextProps())
private var composeView: ComposeView? = null

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class TextFieldView(context: Context, appContext: AppContext) : ExpoView(context
private var props = mutableStateOf(TextFieldProps())
private val onValueChange by EventDispatcher()

override val shouldUseAndroidLayout = true

init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '23')
compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '34')
targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '34')
kotlinVersion = findProperty('android.kotlinVersion') ?: '1.9.24'
kotlinVersion = '1.9.24'

ndkVersion = "26.1.10909125"
}
Expand Down
Loading