Skip to content

Commit

Permalink
Update compose and remove material dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
wingio committed Aug 29, 2024
1 parent dae3fa5 commit d9b98e4
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 190 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ androidx-lifecycle-runtime-ktx = "2.8.4"
# Compose
androidx-activity-compose = "1.9.1"
androidx-paging-compose = "3.3.2"
compose-multiplatform = "1.6.11"
compose-multiplatform = "1.7.0-alpha03"

# KotlinX
kotlinx-coroutines-core = "1.8.1"
Expand Down
1 change: 0 additions & 1 deletion ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ kotlin {
api(libs.bundles.voyager)

api(compose.material3)
api(compose.material)
api(compose.materialIconsExtended)
api(compose.runtime)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun BottomSheet(
tonalElevation = tonalElevation,
scrimColor = scrimColor,
dragHandle = dragHandle,
windowInsets = WindowInsets(0, 0, 0, 0),
contentWindowInsets = { WindowInsets(0, 0, 0, 0) },
content = {
val coroutineScope = rememberCoroutineScope()
val animateToDismiss: () -> Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ 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.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Share
import androidx.compose.material.icons.outlined.ContentCopy
import androidx.compose.material.icons.outlined.Description
import androidx.compose.material.icons.outlined.FormatColorText
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -29,6 +26,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -50,7 +48,6 @@ import com.materiiapps.gloom.gql.fragment.RepoFile
import com.materiiapps.gloom.ui.component.BackButton
import com.materiiapps.gloom.ui.component.DownloadButton
import com.materiiapps.gloom.ui.component.ErrorMessage
import com.materiiapps.gloom.ui.component.RefreshIndicator
import com.materiiapps.gloom.ui.screen.explorer.viewers.ImageFileViewer
import com.materiiapps.gloom.ui.screen.explorer.viewers.MarkdownFileViewer
import com.materiiapps.gloom.ui.screen.explorer.viewers.PdfFileViewer
Expand All @@ -69,13 +66,11 @@ class FileViewerScreen(
) : Screen {

@Composable
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
override fun Content() {
val viewModel: FileViewerViewModel =
getScreenModel { parametersOf(FileViewerViewModel.Input(owner, name, branch, path)) }
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
val pullRefreshState =
rememberPullRefreshState(viewModel.isLoading, onRefresh = viewModel::refresh)
val file = viewModel.file?.gitObject?.onCommit?.file

var topBarHidden by remember {
Expand All @@ -87,11 +82,12 @@ class FileViewerScreen(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
contentWindowInsets = WindowInsets(0, 0, 0, 0)
) { pv ->
Box(
PullToRefreshBox(
isRefreshing = viewModel.isLoading,
onRefresh = { viewModel.refresh() },
modifier = Modifier
.padding(pv)
.fillMaxSize()
.pullRefresh(pullRefreshState)
) {
when (viewModel.fileHasError) {
true -> ErrorMessage(
Expand All @@ -110,8 +106,6 @@ class FileViewerScreen(
}
)
}

RefreshIndicator(pullRefreshState, viewModel.isLoading)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SmallFloatingActionButton
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
Expand All @@ -39,7 +37,6 @@ import cafe.adriel.voyager.navigator.tab.LocalTabNavigator
import cafe.adriel.voyager.navigator.tab.Tab
import cafe.adriel.voyager.navigator.tab.TabOptions
import com.materiiapps.gloom.Res
import com.materiiapps.gloom.ui.component.RefreshIndicator
import com.materiiapps.gloom.ui.component.toolbar.LargeToolbar
import com.materiiapps.gloom.ui.screen.home.viewmodel.HomeViewModel
import com.materiiapps.gloom.ui.screen.home.component.CreatedRepoItem
Expand Down Expand Up @@ -68,16 +65,13 @@ class HomeScreen : Tab {
override fun Content() = Screen()

@Composable
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
private fun Screen(
viewModel: HomeViewModel = getScreenModel()
) {
val items = viewModel.items.collectAsLazyPagingItems()
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val isLoading = items.loadState.refresh == LoadState.Loading
val refreshState = rememberPullRefreshState(isLoading, onRefresh = {
viewModel.refresh(items)
})
val lazyListState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
val canScrollBackToTop by remember { derivedStateOf { lazyListState.canScrollBackward } }
Expand All @@ -100,11 +94,12 @@ class HomeScreen : Tab {
}
}
) { pv ->
Box(
PullToRefreshBox(
isRefreshing = isLoading,
onRefresh = { viewModel.refresh(items) },
modifier = Modifier
.fillMaxSize()
.padding(pv)
.pullRefresh(refreshState)
.nestedScroll(scrollBehavior.nestedScrollConnection)
) {
LazyColumn(
Expand Down Expand Up @@ -193,8 +188,6 @@ class HomeScreen : Tab {
}
}
}

RefreshIndicator(refreshState, isRefreshing = isLoading)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
Expand All @@ -20,7 +18,6 @@ import androidx.paging.compose.itemContentType
import androidx.paging.compose.itemKey
import cafe.adriel.voyager.core.screen.Screen
import com.apollographql.apollo.api.Query
import com.materiiapps.gloom.ui.component.RefreshIndicator
import com.materiiapps.gloom.ui.component.ThinDivider
import com.materiiapps.gloom.ui.component.toolbar.LargeToolbar
import com.materiiapps.gloom.ui.screen.list.viewmodel.BaseListViewModel
Expand All @@ -41,23 +38,21 @@ abstract class BaseListScreen<I : Any, D : Query.Data?, VM : BaseListViewModel<I
override fun Content() = Screen()

@Composable
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
private fun Screen() {
val items = viewModel.items.collectAsLazyPagingItems()
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val isLoading = items.loadState.refresh == LoadState.Loading
val refreshState = rememberPullRefreshState(isLoading, onRefresh = {
items.refresh()
})

Scaffold(
topBar = { TopBar(scrollBehavior) }
) { pv ->
Box(
PullToRefreshBox(
isRefreshing = isLoading,
onRefresh = { items.refresh() },
modifier = Modifier
.fillMaxSize()
.padding(pv)
.pullRefresh(refreshState)
) {
LazyColumn(
modifier = Modifier
Expand All @@ -76,8 +71,6 @@ abstract class BaseListScreen<I : Any, D : Query.Data?, VM : BaseListViewModel<I
}
}
}

RefreshIndicator(refreshState, isRefreshing = isLoading)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.IconButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.HowToReg
import androidx.compose.material.icons.filled.Share
Expand All @@ -39,12 +37,11 @@ import androidx.compose.material.icons.outlined.PersonAddAlt
import androidx.compose.material.icons.outlined.Place
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.Star
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ProvideTextStyle
Expand All @@ -55,6 +52,7 @@ import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
Expand Down Expand Up @@ -87,7 +85,6 @@ import com.materiiapps.gloom.gql.type.SocialAccountProvider
import com.materiiapps.gloom.ui.component.Avatar
import com.materiiapps.gloom.ui.component.BackButton
import com.materiiapps.gloom.ui.component.BadgedItem
import com.materiiapps.gloom.ui.component.RefreshIndicator
import com.materiiapps.gloom.ui.icon.social.Facebook
import com.materiiapps.gloom.ui.icon.social.Hometown
import com.materiiapps.gloom.ui.icon.social.Instagram
Expand Down Expand Up @@ -129,23 +126,22 @@ open class ProfileScreen(
override fun Content() = Screen()

@Composable
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
private fun Screen(
viewModel: ProfileViewModel = getScreenModel { parametersOf(user) }
) {
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
val refreshState =
rememberPullRefreshState(viewModel.isLoading, onRefresh = { viewModel.loadData() })

Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = { TopBar(viewModel, scrollBehavior) }
) { pv ->
Box(
PullToRefreshBox(
isRefreshing = viewModel.isLoading,
onRefresh = { viewModel.loadData() },
modifier = Modifier
.fillMaxSize()
.padding(pv)
.pullRefresh(refreshState)
) {
Column(
Modifier
Expand Down Expand Up @@ -179,8 +175,6 @@ open class ProfileScreen(
Spacer(modifier = Modifier.height(16.dp))
}
}

RefreshIndicator(refreshState, isRefreshing = viewModel.isLoading)
}
}
}
Expand Down
Loading

0 comments on commit d9b98e4

Please sign in to comment.