@@ -22,6 +22,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
2222import androidx.compose.material3.MaterialTheme
2323import androidx.compose.material3.Scaffold
2424import androidx.compose.material3.Text
25+ import androidx.compose.material3.TopAppBarDefaults
2526import androidx.compose.runtime.Composable
2627import androidx.compose.runtime.getValue
2728import androidx.compose.runtime.mutableStateOf
@@ -39,22 +40,23 @@ import com.sebastianneubauer.jsontree.defaultLightColors
3940import com.sebastianneubauer.jsontreesample.ui.theme.JsonTreeTheme
4041import org.jetbrains.compose.ui.tooling.preview.Preview
4142
42-
4343@Composable
4444internal fun App () = JsonTreeTheme {
4545 MainScreen ()
4646}
4747
4848@OptIn(
49- ExperimentalMaterial3Api ::class , ExperimentalFoundationApi ::class , ExperimentalLayoutApi ::class
49+ ExperimentalMaterial3Api ::class ,
50+ ExperimentalFoundationApi ::class ,
51+ ExperimentalLayoutApi ::class
5052)
5153@Composable
52- fun MainScreen () {
53-
54+ private fun MainScreen () {
5455 Scaffold (
5556 modifier = Modifier .safeDrawingPadding(),
5657 topBar = {
5758 CenterAlignedTopAppBar (
59+ colors = TopAppBarDefaults .centerAlignedTopAppBarColors(containerColor = Color .White ),
5860 title = {
5961 Text (
6062 modifier = Modifier .padding(horizontal = 16 .dp),
@@ -68,7 +70,9 @@ fun MainScreen() {
6870 contentWindowInsets = WindowInsets (top = 60 .dp),
6971 ) { padding ->
7072 Column (
71- modifier = Modifier .fillMaxSize().padding(padding)
73+ modifier = Modifier
74+ .fillMaxSize()
75+ .padding(padding)
7276 ) {
7377 var errorMessage: String? by remember { mutableStateOf(null ) }
7478 var json: String by remember { mutableStateOf(simpleJson) }
@@ -78,17 +82,24 @@ fun MainScreen() {
7882 var showItemCount: Boolean by remember { mutableStateOf(true ) }
7983 var expandSingleChildren: Boolean by remember { mutableStateOf(true ) }
8084
81- FlowRow {
82- Button (modifier = Modifier .padding(horizontal = 8 .dp), onClick = {
83- errorMessage = null
84- json = when (json) {
85- emptyJson -> simpleJson
86- simpleJson -> complexJson
87- complexJson -> invalidJson
88- invalidJson -> emptyJson
89- else -> throw IllegalStateException (" No JSON selected!" )
85+ FlowRow (
86+ modifier = Modifier
87+ .fillMaxWidth()
88+ .background(color = Color .White ),
89+ ) {
90+ Button (
91+ modifier = Modifier .padding(horizontal = 8 .dp),
92+ onClick = {
93+ errorMessage = null
94+ json = when (json) {
95+ emptyJson -> simpleJson
96+ simpleJson -> complexJson
97+ complexJson -> invalidJson
98+ invalidJson -> emptyJson
99+ else -> throw IllegalStateException (" No JSON selected!" )
100+ }
90101 }
91- } ) {
102+ ) {
92103 Text (
93104 text = when (json) {
94105 simpleJson -> " Simple Json"
@@ -100,36 +111,47 @@ fun MainScreen() {
100111 )
101112 }
102113
103- Button (modifier = Modifier .padding(horizontal = 8 .dp), onClick = {
104- val newState = when (initialState) {
105- TreeState .EXPANDED -> TreeState .COLLAPSED
106- TreeState .COLLAPSED -> TreeState .FIRST_ITEM_EXPANDED
107- TreeState .FIRST_ITEM_EXPANDED -> TreeState .EXPANDED
114+ Button (
115+ modifier = Modifier .padding(horizontal = 8 .dp),
116+ onClick = {
117+ val newState = when (initialState) {
118+ TreeState .EXPANDED -> TreeState .COLLAPSED
119+ TreeState .COLLAPSED -> TreeState .FIRST_ITEM_EXPANDED
120+ TreeState .FIRST_ITEM_EXPANDED -> TreeState .EXPANDED
121+ }
122+ initialState = newState
108123 }
109- initialState = newState
110- }) {
124+ ) {
111125 Text (text = initialState.name)
112126 }
113127
114- Button (modifier = Modifier .padding(horizontal = 8 .dp),
115- onClick = { showIndices = ! showIndices }) {
128+ Button (
129+ modifier = Modifier .padding(horizontal = 8 .dp),
130+ onClick = { showIndices = ! showIndices }
131+ ) {
116132 Text (text = if (showIndices) " Hide indices" else " Show indices" )
117133 }
118134
119- Button (modifier = Modifier .padding(horizontal = 8 .dp),
120- onClick = { showItemCount = ! showItemCount }) {
135+ Button (
136+ modifier = Modifier .padding(horizontal = 8 .dp),
137+ onClick = { showItemCount = ! showItemCount }
138+ ) {
121139 Text (text = if (showItemCount) " Hide item count" else " Show item count" )
122140 }
123141
124- Button (modifier = Modifier .padding(horizontal = 8 .dp), onClick = {
125- colors =
126- if (colors == defaultLightColors) defaultDarkColors else defaultLightColors
127- }) {
142+ Button (
143+ modifier = Modifier .padding(horizontal = 8 .dp),
144+ onClick = {
145+ colors = if (colors == defaultLightColors) defaultDarkColors else defaultLightColors
146+ }
147+ ) {
128148 Text (text = if (colors == defaultLightColors) " Light" else " Dark" )
129149 }
130150
131- Button (modifier = Modifier .padding(horizontal = 8 .dp),
132- onClick = { expandSingleChildren = ! expandSingleChildren }) {
151+ Button (
152+ modifier = Modifier .padding(horizontal = 8 .dp),
153+ onClick = { expandSingleChildren = ! expandSingleChildren }
154+ ) {
133155 Text (text = if (expandSingleChildren) " Expand children" else " Don't expand children" )
134156 }
135157 }
@@ -147,12 +169,20 @@ fun MainScreen() {
147169 val error = errorMessage
148170 if (error != null ) {
149171 Text (
150- text = error, color = Color .Black
172+ modifier = Modifier
173+ .fillMaxSize()
174+ .background(
175+ color = if (colors == defaultLightColors) Color .White else Color .Black
176+ ),
177+ text = error,
178+ color = if (colors == defaultLightColors) Color .Black else Color .White ,
151179 )
152180 } else {
153181 JsonTree (
154- modifier = Modifier .fillMaxSize()
155- .horizontalScroll(rememberScrollState()).background(
182+ modifier = Modifier
183+ .fillMaxSize()
184+ .horizontalScroll(rememberScrollState())
185+ .background(
156186 if (colors == defaultLightColors) Color .White else Color .Black
157187 ),
158188 contentPadding = PaddingValues (16 .dp),
@@ -191,9 +221,8 @@ fun MainScreen() {
191221 }
192222}
193223
194-
195224@Preview
196225@Composable
197- fun PreviewMainScreen () = JsonTreeTheme {
226+ private fun PreviewMainScreen () = JsonTreeTheme {
198227 MainScreen ()
199228}
0 commit comments