Skip to content

Commit ad73c6c

Browse files
committed
implement MainActivity in sample app to show simple example to use BottomSheetDialog composable
1 parent 1b5d5b5 commit ad73c6c

File tree

5 files changed

+100
-8
lines changed

5 files changed

+100
-8
lines changed

app/build.gradle

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,22 @@ android {
2929
kotlinOptions {
3030
jvmTarget = '1.8'
3131
}
32+
buildFeatures {
33+
compose = true
34+
}
35+
composeOptions {
36+
kotlinCompilerExtensionVersion = "1.2.0-beta02"
37+
}
38+
3239
}
3340

3441
dependencies {
35-
36-
implementation 'androidx.core:core-ktx:1.7.0'
42+
implementation project(":bottomsheetdialog-compose")
43+
implementation 'androidx.compose.ui:ui:1.2.0-beta02'
44+
implementation 'androidx.compose.foundation:foundation:1.2.0-beta02'
45+
implementation 'androidx.compose.material:material:1.2.0-beta02'
46+
implementation 'androidx.activity:activity-compose:1.4.0'
47+
implementation 'androidx.core:core-ktx:1.8.0'
3748
implementation 'androidx.appcompat:appcompat:1.4.2'
3849
implementation 'com.google.android.material:material:1.6.1'
3950
testImplementation 'junit:junit:4.13.2'

app/src/main/AndroidManifest.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4-
package="com.holix.android.bottomsheetdialog">
4+
package="com.holix.android.bottomsheetdialogcomposedemo">
55

66
<application
77
android:allowBackup="true"
@@ -11,7 +11,17 @@
1111
android:label="@string/app_name"
1212
android:roundIcon="@mipmap/ic_launcher_round"
1313
android:supportsRtl="true"
14-
android:theme="@style/Theme.Bottomsheetdialogcompose"
15-
tools:targetApi="31" />
14+
android:theme="@style/Theme.Bottomsheetdialogcomposedemo"
15+
tools:targetApi="31">
16+
<activity
17+
android:name=".MainActivity"
18+
android:exported="true">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
1626

1727
</manifest>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.holix.android.bottomsheetdialogcomposedemo
2+
3+
import android.os.Bundle
4+
import androidx.activity.compose.setContent
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.compose.foundation.isSystemInDarkTheme
7+
import androidx.compose.foundation.layout.*
8+
import androidx.compose.foundation.shape.RoundedCornerShape
9+
import androidx.compose.material.*
10+
import androidx.compose.runtime.getValue
11+
import androidx.compose.runtime.mutableStateOf
12+
import androidx.compose.runtime.saveable.rememberSaveable
13+
import androidx.compose.runtime.setValue
14+
import androidx.compose.ui.Alignment
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.unit.dp
17+
import com.holix.android.bottomsheetdialog.compose.BottomSheetDialog
18+
import com.holix.android.bottomsheetdialog.compose.BottomSheetDialogProperties
19+
20+
class MainActivity : AppCompatActivity() {
21+
override fun onCreate(savedInstanceState: Bundle?) {
22+
super.onCreate(savedInstanceState)
23+
setContent {
24+
MaterialTheme(
25+
colors = if (isSystemInDarkTheme()) {
26+
darkColors()
27+
} else {
28+
lightColors()
29+
}
30+
) {
31+
var showBottomSheetDialog by rememberSaveable {
32+
mutableStateOf(false)
33+
}
34+
if (showBottomSheetDialog) {
35+
BottomSheetDialog(
36+
onDismissRequest = {
37+
showBottomSheetDialog = false
38+
},
39+
properties = BottomSheetDialogProperties(
40+
navigationBarColor = MaterialTheme.colors.surface
41+
)
42+
) {
43+
Surface(
44+
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)
45+
) {
46+
Column(
47+
modifier = Modifier
48+
.fillMaxWidth()
49+
.padding(16.dp),
50+
verticalArrangement = Arrangement.spacedBy(16.dp)
51+
) {
52+
Text(text = "Title", style = MaterialTheme.typography.h5)
53+
repeat(5) { index ->
54+
Text(text = "Item $index", style = MaterialTheme.typography.body1)
55+
}
56+
}
57+
}
58+
}
59+
}
60+
Box(
61+
modifier = Modifier.fillMaxSize(),
62+
contentAlignment = Alignment.Center
63+
) {
64+
Button(onClick = { showBottomSheetDialog = true }) {
65+
Text(text = "Show")
66+
}
67+
}
68+
}
69+
}
70+
}
71+
}

app/src/main/res/values/themes.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
22
<!-- Base application theme. -->
3-
<style name="Theme.Bottomsheetdialogcompose" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
3+
<style name="Theme.Bottomsheetdialogcomposedemo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
44
<!-- Primary brand color. -->
55
<item name="colorPrimary">@color/purple_500</item>
66
<item name="colorPrimaryVariant">@color/purple_700</item>
@@ -10,7 +10,7 @@
1010
<item name="colorSecondaryVariant">@color/teal_700</item>
1111
<item name="colorOnSecondary">@color/black</item>
1212
<!-- Status bar color. -->
13-
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
13+
<item name="android:statusBarColor" >?attr/colorPrimaryVariant</item>
1414
<!-- Customize your theme here. -->
1515
</style>
1616
</resources>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
plugins {
33
id 'com.android.application' version '7.2.1' apply false
44
id 'com.android.library' version '7.2.1' apply false
5-
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
5+
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
66
}
77

88
task clean(type: Delete) {

0 commit comments

Comments
 (0)