@@ -19,6 +19,7 @@ import androidx.compose.material3.Text
1919import androidx.compose.material3.darkColorScheme
2020import androidx.compose.material3.lightColorScheme
2121import androidx.compose.runtime.Composable
22+ import androidx.compose.runtime.CompositionLocalProvider
2223import androidx.compose.runtime.LaunchedEffect
2324import androidx.compose.runtime.getValue
2425import androidx.compose.runtime.mutableStateOf
@@ -27,7 +28,9 @@ import androidx.compose.runtime.setValue
2728import androidx.compose.ui.Alignment
2829import androidx.compose.ui.Modifier
2930import androidx.compose.ui.platform.LocalContext
31+ import androidx.compose.ui.platform.LocalLayoutDirection
3032import androidx.compose.ui.tooling.preview.Preview
33+ import androidx.compose.ui.unit.LayoutDirection
3134import androidx.compose.ui.unit.dp
3235import com.halilibo.richtext.commonmark.CommonmarkAstNodeParser
3336import 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 }
0 commit comments