Rafael Moreira
Rafael Moreira

Reputation: 430

Jetpack Compose Full-Screen Dialog Extends Beyond Screen Bottom on Some Devices

I'm trying to understand what is causing this behaviour in a full-screen dialog. When I test on a pixel6 emulator, it's all good. Also in an Android10. On the pixel7, not so much. Both images are below.

I've tried using window insets, but I might not understand plainly. There are no error messages. I've tried to use a surface instead of a Box.

I know that if I remove the dialog and turn into another screen composable would work, but I need to know how this full-screen dialog works in different scenarios. Could be a version situation, but still I want to figure out how to proceed here.

I'm using the last stable version for everything in this app.

Pixel7 at left and pixel6 at right.

Pixel7 Pixel6

Here's the composable code.


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ListTipListScreen(
    viewModel: MainScreenViewModel,
    onDismissRequest: () -> Unit,
    listId: Int,
    onBackClick: () -> Unit,
) {
    val list = viewModel
        .getListById(listId)
        .collectAsState(null)

    /** Get the list of tips for the List collected on variable "list" above */
    val listTipList by viewModel
        .getAllTipsFromList(listId)
        .collectAsState(emptyList())

    /** Share the list of tips using [shareTextWithApps] */
    val context = LocalContext.current

    Dialog(
        onDismissRequest = { onDismissRequest() },
        properties = DialogProperties(
            usePlatformDefaultWidth = false,
            dismissOnBackPress = true,
            decorFitsSystemWindows = false,
            dismissOnClickOutside = false
        )
    ) {
        Scaffold(
            topBar = {
                CenterAlignedTopAppBar(
                    colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
                        containerColor = MaterialTheme.colorScheme.surfaceTint.copy(alpha = 0.1f),
                    ),
                    title = { list.value?.let {
                        Text(text = it.name) }
                    },
                    navigationIcon = {
                        IconButton(
                            onClick = onBackClick
                        ) {
                            Icon(
                                imageVector = Icons.AutoMirrored.Filled.ArrowBack,
                                contentDescription = stringResource(R.string.back)
                            )
                        }
                    }
                )
            },

            /** FAB to add a final tip value without calculation, to the current List
             * and visualized inside [ListTipListScreen] *
             **/
            floatingActionButton = {
                FabAdd(
                    onClick = { viewModel.updateShowAddTipValueToListDialog(true) },
                    contentDescription = stringResource(R.string.add_tip_to_list)
                )
            },
            floatingActionButtonPosition = FabPosition.End
        ) { innerPadding ->
            Box(
                modifier = Modifier
                    .fillMaxSize()
                    .padding(innerPadding)
            ) {
                Column(
                    modifier = Modifier
                        .padding(dimensionResource(R.dimen.padding_mid))
                ) {
                    Row(
                        modifier = Modifier.fillMaxWidth(),
                        horizontalArrangement = Arrangement.SpaceBetween,
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        Text(
                            text = stringResource(R.string.tip_list_title),
                            style = MaterialTheme.typography.titleLarge,
                            modifier = Modifier.padding(dimensionResource(R.dimen.padding_sml))
                        )

                        /**
                         * Button to [shareTextWithApps]. Sharing list of Tips from List
                         */
                        Icon(
                            modifier = Modifier
                                .size(24.dp)
                                .clickable {
                                    shareTextWithApps(
                                        title = list.value?.name!!,
                                        content = tipListToString(listTipList),
                                        context = context
                                    )
                                },
                            imageVector = Icons.Default.Share,
                            tint = MaterialTheme.colorScheme.primary,
                            contentDescription = stringResource(R.string.share_tip_list)
                        )
                    }
                    HorizontalDivider(
                        modifier = Modifier
                            .padding(bottom = dimensionResource(R.dimen.padding_mid))
                    )
                    LazyColumn(
                        userScrollEnabled = true
                    ) {

                        /**
                         * Display rows of tips from specific List(List).
                         */
                        itemsIndexed(listTipList) { _, tip ->
                            ListItemComponent(
                                overLineContent = { Text(text = tip.dateCreated) },
                                item = tip,
                                getName = { tip.tipAmount },
                                mainTrailItemInfo = { },
                                listItemTrailingIcon = Icons.Default.DeleteForever,
                                trailingIconContentDescription = stringResource(R.string.delete),
                                onClickTrailingIcon = { viewModel.deleteTip(tip) },
                                onClickLabel = context.getString(R.string.tip_will_be_deleted),
                                modifier = Modifier.height(70.dp)
                            )
                        }
                    }
                }

                /** Conditional attached to [FabAdd] composable above to
                 * show dialog when clicked
                 */
                if(viewModel.showAddTipValueToListDialog) {
                    AddTipValueToListDialog(
                        viewModel = viewModel,
                        onSaveRequest = {
                            viewModel.viewModelScope.launch {
                                viewModel.insertTipValueToList(listId)
                                viewModel.updateShowAddTipValueToListDialog(false)
                            }
                        }
                    )
                }
            }
        }
    }
}

Upvotes: 0

Views: 27

Answers (0)

Related Questions