Last active
July 15, 2021 14:17
-
-
Save mitchtabian/7d65d1b5e7bfdba95120bd4dc751c4d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Align composables with respect to one another | |
@Composable | |
fun CircularIndeterminateProgressBar(isDisplayed: Boolean) { | |
if (isDisplayed) { | |
ConstraintLayout( | |
modifier = Modifier.fillMaxSize() | |
) { | |
val (progress, text) = createRefs() | |
CircularProgressIndicator( | |
modifier = Modifier.constrainAs(progress) { | |
top.linkTo(parent.top) | |
bottom.linkTo(parent.bottom) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
}, | |
color = MaterialTheme.colors.primary | |
) | |
Text( | |
text = "Loading", | |
style = TextStyle( | |
color = Color.Black, | |
fontSize = TextUnit.Companion.Sp(15) | |
), | |
modifier = Modifier.constrainAs(text){ | |
top.linkTo(progress.bottom) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
} | |
) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// guideline from top | |
@Composable | |
fun CircularIndeterminateProgressBar(isDisplayed: Boolean) { | |
if (isDisplayed) { | |
ConstraintLayout( | |
modifier = Modifier.fillMaxSize() | |
) { | |
val (progress, text) = createRefs() | |
val topGuideline = createGuidelineFromTop(0.3f) | |
CircularProgressIndicator( | |
modifier = Modifier.constrainAs(progress) { | |
top.linkTo(topGuideline) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
}, | |
color = MaterialTheme.colors.primary | |
) | |
Text( | |
text = "Loading", | |
style = TextStyle( | |
color = Color.Black, | |
fontSize = TextUnit.Companion.Sp(15) | |
), | |
modifier = Modifier.constrainAs(text){ | |
top.linkTo(progress.bottom) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
} | |
) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// guideline from bottom | |
@Composable | |
fun CircularIndeterminateProgressBar(isDisplayed: Boolean) { | |
if (isDisplayed) { | |
ConstraintLayout( | |
modifier = Modifier.fillMaxSize() | |
) { | |
val (progress, text) = createRefs() | |
val topGuideline = createGuidelineFromBottom(0.3f) | |
CircularProgressIndicator( | |
modifier = Modifier.constrainAs(progress) { | |
bottom.linkTo(topGuideline) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
}, | |
color = MaterialTheme.colors.primary | |
) | |
Text( | |
text = "Loading", | |
style = TextStyle( | |
color = Color.Black, | |
fontSize = TextUnit.Companion.Sp(15) | |
), | |
modifier = Modifier.constrainAs(text){ | |
top.linkTo(progress.bottom) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
} | |
) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// decoupled constraints | |
@Composable | |
fun CircularIndeterminateProgressBar(isDisplayed: Boolean) { | |
if (isDisplayed) { | |
WithConstraints( | |
modifier = Modifier.fillMaxSize() | |
) { | |
Log.d(TAG, "CircularIndeterminateProgressBar: ${minWidth}") | |
val constraints = if(minWidth < 600.dp){ | |
myDecoupledConstraints(.3f) // Portrait | |
} | |
else{ | |
myDecoupledConstraints(.7f) // Landscape | |
} | |
ConstraintLayout( | |
modifier = Modifier.fillMaxSize(), | |
constraintSet = constraints, | |
) { | |
CircularProgressIndicator( | |
modifier = Modifier.layoutId("progressBar"), | |
color = MaterialTheme.colors.primary | |
) | |
Text( | |
text = "Loading", | |
style = TextStyle( | |
color = Color.Black, | |
fontSize = TextUnit.Companion.Sp(15) | |
), | |
modifier = Modifier.layoutId("loadingText"), | |
) | |
} | |
} | |
} | |
} | |
private fun myDecoupledConstraints(verticalBias: Float): ConstraintSet { | |
return ConstraintSet { | |
val guideLine = createGuidelineFromTop(verticalBias) | |
val progressBar = createRefFor("progressBar") | |
val text = createRefFor("loadingText") | |
constrain(progressBar) { | |
top.linkTo(guideLine) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
} | |
constrain(text) { | |
top.linkTo(progressBar.bottom) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment