Skip to content

Commit

Permalink
fix(ui): webview renderer nested scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Sep 26, 2024
1 parent d219307 commit b2fbcb6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 41 deletions.
112 changes: 73 additions & 39 deletions app/src/main/java/me/ash/reader/ui/page/home/reading/Content.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.selection.DisableSelection
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.unit.dp
import me.ash.reader.infrastructure.preference.LocalOpenLink
import me.ash.reader.infrastructure.preference.LocalOpenLinkSpecificBrowser
Expand Down Expand Up @@ -60,47 +65,74 @@ fun Content(
}
} else {

SelectionContainer {
LazyColumn(
modifier = modifier
.fillMaxSize()
.drawVerticalScrollbar(listState),
state = listState,
) {
item {
// Top bar height
Spacer(modifier = Modifier.height(64.dp))
// padding
Spacer(modifier = Modifier.height(22.dp))
Column(
modifier = Modifier
.padding(horizontal = 12.dp)
) {
DisableSelection {
Metadata(
feedName = feedName,
title = title,
author = author,
link = link,
publishedDate = publishedDate,
)
when (renderer) {
ReadingRendererPreference.WebView -> {
Column(modifier = modifier) {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
// Top bar height
Spacer(modifier = Modifier.height(64.dp))
// padding
Spacer(modifier = Modifier.height(22.dp))
Column(
modifier = Modifier
.padding(horizontal = 12.dp)
) {
DisableSelection {
Metadata(
feedName = feedName,
title = title,
author = author,
link = link,
publishedDate = publishedDate,
)
}
}
Spacer(modifier = Modifier.height(22.dp))

RYWebView(
modifier = Modifier.fillMaxWidth(),
content = content,
refererDomain = link.extractDomain(),
onImageClick = onImageClick,
)
Spacer(modifier = Modifier.height(128.dp))
Spacer(modifier = Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars))

}
Spacer(modifier = Modifier.height(22.dp))
}

when (renderer) {
ReadingRendererPreference.WebView -> {
}

ReadingRendererPreference.NativeComponent -> {
SelectionContainer {
LazyColumn(
modifier = modifier
.fillMaxSize()
.drawVerticalScrollbar(listState),
state = listState,
) {
item {
RYWebView(
content = content,
refererDomain = link.extractDomain(),
onImageClick = onImageClick,
)
// Top bar height
Spacer(modifier = Modifier.height(64.dp))
// padding
Spacer(modifier = Modifier.height(22.dp))
Column(
modifier = Modifier
.padding(horizontal = 12.dp)
) {
DisableSelection {
Metadata(
feedName = feedName,
title = title,
author = author,
link = link,
publishedDate = publishedDate,
)
}
}
Spacer(modifier = Modifier.height(22.dp))
}
}

ReadingRendererPreference.NativeComponent -> {
Reader(
context = context,
subheadUpperCase = subheadUpperCase.value,
Expand All @@ -111,14 +143,16 @@ fun Content(
context.openURL(it, openLink, openLinkSpecificBrowser)
}
)
}
}

item {
Spacer(modifier = Modifier.height(128.dp))
Spacer(modifier = Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars))
item {
Spacer(modifier = Modifier.height(128.dp))
Spacer(modifier = Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars))
}
}
}
}
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private class ReaderNestedScrollConnection(
!enabled || available.y == 0f -> Offset.Zero

// Scroll down to reduce the progress when the offset is currently pulled up, same for the opposite
source == Drag -> {
source == NestedScrollSource.UserInput -> {
Offset(0f, onPreScroll(available.y))
}

Expand All @@ -78,7 +78,7 @@ private class ReaderNestedScrollConnection(
consumed: Offset, available: Offset, source: NestedScrollSource
): Offset = when {
!enabled -> Offset.Zero
source == Drag -> Offset(0f, onPostScroll(available.y)) // Pull to load
source == NestedScrollSource.UserInput -> Offset(0f, onPostScroll(available.y)) // Pull to load
else -> Offset.Zero
}

Expand Down

0 comments on commit b2fbcb6

Please sign in to comment.