Skip to content

Commit

Permalink
Merge branch 'main' into jv/jn_improvs
Browse files Browse the repository at this point in the history
  • Loading branch information
JolandaVerhoef authored May 12, 2021
2 parents 521bd77 + 85244da commit a668bf0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import com.example.jetnews.ui.components.InsetAwareTopAppBar
import com.example.jetnews.ui.home.BookmarkButton
import com.example.jetnews.ui.theme.JetnewsTheme
import com.example.jetnews.utils.produceUiState
import com.example.jetnews.utils.supportWideScreen
import com.google.accompanist.insets.navigationBarsPadding
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -163,6 +164,8 @@ fun ArticleScreen(
.padding(innerPadding)
// offset content in landscape mode to account for the navigation bar
.navigationBarsPadding(bottom = false)
// center content in landscape mode
.supportWideScreen()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import com.example.jetnews.ui.components.InsetAwareTopAppBar
import com.example.jetnews.ui.state.UiState
import com.example.jetnews.ui.theme.JetnewsTheme
import com.example.jetnews.utils.produceUiState
import com.example.jetnews.utils.supportWideScreen
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.toPaddingValues
import com.google.accompanist.swiperefresh.SwipeRefresh
Expand Down Expand Up @@ -194,7 +195,7 @@ fun HomeScreen(
navigateToArticle = navigateToArticle,
favorites = favorites,
onToggleFavorite = onToggleFavorite,
modifier = modifier
modifier = modifier.supportWideScreen()
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -62,6 +64,7 @@ import com.example.jetnews.data.interests.impl.FakeInterestsRepository
import com.example.jetnews.ui.components.InsetAwareTopAppBar
import com.example.jetnews.ui.theme.JetnewsTheme
import com.example.jetnews.utils.produceUiState
import com.example.jetnews.utils.supportWideScreen
import com.google.accompanist.insets.navigationBarsPadding
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -235,7 +238,7 @@ private fun TabContent(
Divider(
color = MaterialTheme.colors.onSurface.copy(alpha = 0.1f)
)
Box(modifier = Modifier.weight(1f)) {
Box(modifier = Modifier.weight(1f).supportWideScreen()) {
// display the current tab content which is a @Composable () -> Unit
tabContent[selectedTabIndex].content()
}
Expand Down Expand Up @@ -336,7 +339,7 @@ private fun TabWithSections(
item {
Text(
text = section,
modifier = Modifier.padding(16.dp),
modifier = Modifier.padding(16.dp).semantics { heading() },
style = MaterialTheme.typography.subtitle1
)
}
Expand Down
32 changes: 32 additions & 0 deletions JetNews/app/src/main/java/com/example/jetnews/utils/Modifiers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2021 The Android Open Source Project
*
* 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
*
* https://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.example.jetnews.utils

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

/**
* Support wide screen by making the content width max 840dp, centered horizontally.
*/
fun Modifier.supportWideScreen() = this
.fillMaxWidth()
.wrapContentWidth(align = Alignment.CenterHorizontally)
.widthIn(max = 840.dp)

0 comments on commit a668bf0

Please sign in to comment.