Skip to content

Enhance NewModuleScript Template #344

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

Merged
merged 8 commits into from
Apr 21, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,106 @@

package com.esri.arcgismaps.sample.sampleslib.components

import android.content.res.Configuration
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.FilledTonalIconButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme

/**
* Composable component used to display a custom bottom sheet for samples.
* The bottom sheet can display any @Composable content passed to the [bottomSheetContent],
* and the visibility can be toggled using [isVisible]
* and the visibility can be toggled using [isVisible].
*
* Optionally, pass a [sheetTitle] to display a close Icon which provides an [onDismissRequest].
*/
@Composable
fun BottomSheet(
isVisible: Boolean,
bottomSheetContent: @Composable () -> Unit
sheetTitle: String = "",
onDismissRequest: () -> Unit = { },
bottomSheetContent: @Composable (ColumnScope) -> Unit
) {
Box(
modifier = Modifier.fillMaxSize()
) {
AnimatedVisibility(
modifier = Modifier.align(Alignment.BottomCenter),
visible = isVisible,
enter = slideInVertically{height -> height} + fadeIn(),
exit = slideOutVertically{height -> height} + fadeOut()
enter = slideInVertically { height -> height } + fadeIn(),
exit = slideOutVertically { height -> height } + fadeOut()
) {
SampleAppTheme {
Surface {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
if (sheetTitle != "") {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(12.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = sheetTitle,
style = MaterialTheme.typography.titleLarge
)
FilledTonalIconButton(onClick = onDismissRequest) {
Icon(Icons.Filled.Close, contentDescription = "CloseSheetIcon")
}
}
}
bottomSheetContent(this)
Spacer(Modifier.height(12.dp))
}
}
}
}
}
}

@Preview(showBackground = true)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
@Composable
fun BottomSheetPreview() {
SamplePreviewSurface {
BottomSheet(
sheetTitle = "Bottom sheet options:",
isVisible = true
) {
bottomSheetContent()
DropDownMenuBox(
textFieldValue = "<selected-option>",
textFieldLabel = "Select an option",
dropDownItemList = emptyList(),
onIndexSelected = { }
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* Copyright 2025 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.esri.arcgismaps.sample.sampleslib.components

import android.content.res.Configuration
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties

/**
* A simplified implementation of the [Dialog] with layout all the dialog UI
* style configurations to display the [content] using the default [properties].
*/
@Composable
fun SampleDialog(
modifier: Modifier = Modifier,
properties: DialogProperties = DialogProperties(),
onDismissRequest: () -> Unit,
content: @Composable (ColumnScope) -> Unit
) {
Dialog(onDismissRequest = onDismissRequest, properties = properties) {
Column(
modifier = modifier
.clip(RoundedCornerShape(12.dp))
.background(MaterialTheme.colorScheme.background)
.padding(12.dp)
.fillMaxWidth()
.verticalScroll(rememberScrollState())
.animateContentSize(),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
content(this)
}
}
}

@Preview(showBackground = true)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
@Composable
fun DialogOptionsPreview() {
SamplePreviewSurface {
SampleDialog(onDismissRequest = {}) {
Text("Sample options: ", style = MaterialTheme.typography.titleMedium)
DropDownMenuBox(
textFieldValue = "Current selection",
textFieldLabel = "Select an option",
dropDownItemList = emptyList(),
onIndexSelected = { }
)
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
OutlinedButton(onClick = { }) { Text("Dismiss") }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Copyright 2025 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.esri.arcgismaps.sample.sampleslib.components

import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme

/**
* Helper composable to apply sample theme to the given [content] for previews.
*/
@Composable
fun SamplePreviewSurface(content: @Composable () -> Unit) {
SampleAppTheme {
Surface { content() }
}
}
Binary file modified tools/NewModuleScript.jar
Binary file not shown.
129 changes: 129 additions & 0 deletions tools/NewModuleScript/MainScreenDialogTemplate.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/* Copyright 2023 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.esri.arcgismaps.sample.displaycomposablemapview.screens

import android.content.res.Configuration
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.arcgismaps.toolkit.geoviewcompose.MapView
import com.esri.arcgismaps.sample.displaycomposablemapview.components.MapViewModel
import com.esri.arcgismaps.sample.sampleslib.components.DropDownMenuBox
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialog
import com.esri.arcgismaps.sample.sampleslib.components.SampleDialog
import com.esri.arcgismaps.sample.sampleslib.components.SamplePreviewSurface
import com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar

/**
* Main screen layout for the sample app
*/
@Composable
fun MainScreen(sampleName: String) {
val mapViewModel: MapViewModel = viewModel()
var isDialogOptionsVisible by remember { mutableStateOf(false) }

Scaffold(
topBar = { SampleTopAppBar(title = sampleName) },
floatingActionButton = {
if (!isDialogOptionsVisible) {
FloatingActionButton(
modifier = Modifier.padding(bottom = 36.dp, end = 12.dp),
onClick = { isDialogOptionsVisible = true }
) { Icon(Icons.Filled.Settings, contentDescription = "Show options") }
}
},
content = {
Column(
modifier = Modifier
.fillMaxSize()
.padding(it),
) {
MapView(
modifier = Modifier
.fillMaxSize()
.weight(1f),
arcGISMap = mapViewModel.arcGISMap
)
}

if (isDialogOptionsVisible) {
DialogOptions(
// isCurrentOptionEnabled = ...,
// onOptionToggled = { ... }
onDismissRequest = { isDialogOptionsVisible = false }
)
}

mapViewModel.messageDialogVM.apply {
if (dialogStatus) {
MessageDialog(
title = messageTitle,
description = messageDescription,
onDismissRequest = ::dismissDialog
)
}
}
}
)
}

@Composable
fun DialogOptions(
onDismissRequest: () -> Unit
) {
SampleDialog(onDismissRequest = onDismissRequest) {
Text("Sample options: ", style = MaterialTheme.typography.titleMedium)
DropDownMenuBox(
textFieldValue = "<selected-option>",
textFieldLabel = "Select an option",
dropDownItemList = emptyList(),
onIndexSelected = { }
)
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
OutlinedButton(onClick = onDismissRequest) { Text("Dismiss") }
}
}
}

@Preview(showBackground = true)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
@Composable
fun DialogOptionsPreview() {
SamplePreviewSurface {
DialogOptions { }
}
}
Loading
Loading