Skip to content

Commit bbc25a2

Browse files
authored
Merge pull request #133 from halilozercan/halilozercan/fix-rtl-lists
Fix #109
2 parents 358d370 + eeb73eb commit bbc25a2

2 files changed

Lines changed: 66 additions & 51 deletions

File tree

android-sample/src/main/java/com/zachklipp/richtext/sample/MarkdownSample.kt

Lines changed: 64 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.compose.material3.Text
1919
import androidx.compose.material3.darkColorScheme
2020
import androidx.compose.material3.lightColorScheme
2121
import androidx.compose.runtime.Composable
22+
import androidx.compose.runtime.CompositionLocalProvider
2223
import androidx.compose.runtime.LaunchedEffect
2324
import androidx.compose.runtime.getValue
2425
import androidx.compose.runtime.mutableStateOf
@@ -27,7 +28,9 @@ import androidx.compose.runtime.setValue
2728
import androidx.compose.ui.Alignment
2829
import androidx.compose.ui.Modifier
2930
import androidx.compose.ui.platform.LocalContext
31+
import androidx.compose.ui.platform.LocalLayoutDirection
3032
import androidx.compose.ui.tooling.preview.Preview
33+
import androidx.compose.ui.unit.LayoutDirection
3134
import androidx.compose.ui.unit.dp
3235
import com.halilibo.richtext.commonmark.CommonmarkAstNodeParser
3336
import com.halilibo.richtext.commonmark.MarkdownParseOptions
@@ -48,6 +51,7 @@ import com.halilibo.richtext.ui.resolveDefaults
4851
var isWordWrapEnabled by remember { mutableStateOf(true) }
4952
var markdownParseOptions by remember { mutableStateOf(MarkdownParseOptions.Default) }
5053
var isAutolinkEnabled by remember { mutableStateOf(true) }
54+
var isRtl by remember { mutableStateOf(false) }
5155

5256
LaunchedEffect(isWordWrapEnabled) {
5357
richTextStyle = richTextStyle.copy(
@@ -65,61 +69,72 @@ import com.halilibo.richtext.ui.resolveDefaults
6569
val colors = if (isDarkModeEnabled) darkColorScheme() else lightColorScheme()
6670
val context = LocalContext.current
6771

68-
SampleTheme(colorScheme = colors) {
69-
Surface {
70-
Column {
71-
// Config
72-
Card(elevation = CardDefaults.elevatedCardElevation()) {
73-
Column {
74-
FlowRow {
75-
CheckboxPreference(
76-
onClick = {
77-
isDarkModeEnabled = !isDarkModeEnabled
78-
},
79-
checked = isDarkModeEnabled,
80-
label = "Dark Mode"
81-
)
82-
CheckboxPreference(
83-
onClick = {
84-
isWordWrapEnabled = !isWordWrapEnabled
85-
},
86-
checked = isWordWrapEnabled,
87-
label = "Word Wrap"
88-
)
89-
CheckboxPreference(
90-
onClick = {
91-
isAutolinkEnabled = !isAutolinkEnabled
92-
},
93-
checked = isAutolinkEnabled,
94-
label = "Autolink"
72+
CompositionLocalProvider(
73+
LocalLayoutDirection provides if (isRtl) LayoutDirection.Rtl else LayoutDirection.Ltr
74+
) {
75+
SampleTheme(colorScheme = colors) {
76+
Surface {
77+
Column {
78+
// Config
79+
Card(elevation = CardDefaults.elevatedCardElevation()) {
80+
Column {
81+
FlowRow {
82+
CheckboxPreference(
83+
onClick = {
84+
isDarkModeEnabled = !isDarkModeEnabled
85+
},
86+
checked = isDarkModeEnabled,
87+
label = "Dark Mode"
88+
)
89+
CheckboxPreference(
90+
onClick = {
91+
isWordWrapEnabled = !isWordWrapEnabled
92+
},
93+
checked = isWordWrapEnabled,
94+
label = "Word Wrap"
95+
)
96+
CheckboxPreference(
97+
onClick = {
98+
isAutolinkEnabled = !isAutolinkEnabled
99+
},
100+
checked = isAutolinkEnabled,
101+
label = "Autolink"
102+
)
103+
CheckboxPreference(
104+
onClick = {
105+
isRtl = !isRtl
106+
},
107+
checked = isRtl,
108+
label = "RTL Layout"
109+
)
110+
}
111+
112+
RichTextStyleConfig(
113+
richTextStyle = richTextStyle,
114+
onChanged = { richTextStyle = it }
95115
)
96116
}
97-
98-
RichTextStyleConfig(
99-
richTextStyle = richTextStyle,
100-
onChanged = { richTextStyle = it }
101-
)
102117
}
103-
}
104118

105-
SelectionContainer {
106-
Column(Modifier.verticalScroll(rememberScrollState())) {
107-
val parser = remember(markdownParseOptions) {
108-
CommonmarkAstNodeParser(markdownParseOptions)
109-
}
119+
SelectionContainer {
120+
Column(Modifier.verticalScroll(rememberScrollState())) {
121+
val parser = remember(markdownParseOptions) {
122+
CommonmarkAstNodeParser(markdownParseOptions)
123+
}
110124

111-
val astNode = remember(parser) {
112-
parser.parse(sampleMarkdown)
113-
}
125+
val astNode = remember(parser) {
126+
parser.parse(sampleMarkdown)
127+
}
114128

115-
RichText(
116-
style = richTextStyle,
117-
linkClickHandler = {
118-
Toast.makeText(context, it, Toast.LENGTH_SHORT).show()
119-
},
120-
modifier = Modifier.padding(8.dp),
121-
) {
122-
BasicMarkdown(astNode)
129+
RichText(
130+
style = richTextStyle,
131+
linkClickHandler = {
132+
Toast.makeText(context, it, Toast.LENGTH_SHORT).show()
133+
},
134+
modifier = Modifier.padding(8.dp),
135+
) {
136+
BasicMarkdown(astNode)
137+
}
123138
}
124139
}
125140
}

richtext-ui/src/commonMain/kotlin/com/halilibo/richtext/ui/FormattedList.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ private val LocalListLevel = compositionLocalOf { 0 }
293293
layoutDirection = layoutDirection
294294
)
295295

296-
prefix.place(prefixOffset.x, y + prefixOffset.y)
297-
item.place(widestPrefix.width, y)
296+
prefix.placeRelative(prefixOffset.x, y + prefixOffset.y)
297+
item.placeRelative(widestPrefix.width, y)
298298
y += rowHeight
299299
}
300300
}

0 commit comments

Comments
 (0)