Skip to content
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

Fix header being flipped for Arabic #3024

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.min
import androidx.compose.ui.unit.sp
Expand All @@ -20,13 +23,21 @@ fun QuranHeaderFooter(
color: Color,
modifier: Modifier = Modifier,
) {
BoxWithConstraints {
val fontSize = (min(this.maxWidth, 480.dp) * 0.0345f).value.sp
Row(modifier = modifier.padding(vertical = 2.dp)) {
val textStyle = MaterialTheme.typography.subtitle2.copy(fontSize = fontSize)
Text(left, style = textStyle, color = color)
Spacer(modifier = Modifier.weight(1f, true))
Text(right, style = textStyle, color = color)
// always render the footer as LTR, otherwise, the page number will be rendered
// on the wrong side of the page for RTL due to Row being smart and flipping the
// children based on LTR/RTL. We want this flipping for the header and footer
// so that the page number is always on the right side for odd numbered
// pages and always on the left side for even numbered pages, and likewise with
// the juz' number and sura name.
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
BoxWithConstraints {
val fontSize = (min(this.maxWidth, 480.dp) * 0.0345f).value.sp
Row(modifier = modifier.padding(vertical = 2.dp)) {
val textStyle = MaterialTheme.typography.subtitle2.copy(fontSize = fontSize)
Text(left, style = textStyle, color = color)
Spacer(modifier = Modifier.weight(1f, true))
Text(right, style = textStyle, color = color)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Spacer
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import com.quran.data.source.PageContentType
import com.quran.labs.androidquran.extra.feature.linebyline.model.PageInfo
import com.quran.labs.androidquran.extra.feature.linebyline.model.SidelinesPosition
Expand Down Expand Up @@ -135,19 +132,12 @@ fun QuranPageWrapper(
"" to displayInfo.localizedPageText
}

// always render the footer as LTR, otherwise, the page number will be rendered
// on the wrong side of the page for RTL due to Row being smart and flipping the
// children based on LTR/RTL. We want this flipping for the header, but not for
// the footer, so that the page number is always on the right side for odd numbered
// pages and always on the left side for even numbered pages.
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
QuranHeaderFooter(
leftText,
rightText,
overlayColor,
modifier = Modifier
)
}
QuranHeaderFooter(
leftText,
rightText,
overlayColor,
modifier = Modifier
)
} else {
Spacer(modifier = Modifier)
}
Expand Down
Loading