Ttop
09/10/2020, 2:39 PMclass TabContent(val header: String, val icon: Int, val content: @Composable () -> Unit)
@Composable
fun BodyContent() {
var index = 0
val updateTab : (currentIndex: Int) -> Unit = { index = it }
val tabs = listOf(
TabContent(
header = stringResource(id = R.string.depenses_tab_title).toUpperCase(
Locale.getDefault()
),
icon = R.drawable.ic_depenses
) { DepenseTabContent(Modifier) },
TabContent(
header = stringResource(id = R.string.equilibre_tab_title).toUpperCase(
Locale.getDefault()
),
icon = R.drawable.ic_equilibres
) { Text ( text= "blop") }
)
BodyContent(index, updateTab, tabs)
}
@Composable
fun BodyContent(
selectedTabIndex: Int,
updateTab: (Int) -> Unit,
tabs: List<TabContent>,
modifier: Modifier = Modifier
) {
Column(modifier.fillMaxSize()) {
TabRow(selectedTabIndex = selectedTabIndex) {
tabs.forEachIndexed { index, tabContent ->
Tab(
selected = selectedTabIndex == index,
onClick = { updateTab(index) },
text = { Text(text = tabContent.header) },
icon = {
Icon(
vectorResource(id = tabContent.icon),
Modifier.width(24.dp).height(24.dp)
)
}
)
}
}
Box {
tabs[selectedTabIndex].content
}
}
}
My tab content is never displayed and I can’t refresh it by clicking in the tabRow. I don’t understand what I’v done wrong.Nat Strangerweather
09/10/2020, 4:16 PMjaqxues
09/10/2020, 4:22 PMSwitch
invokes the onChangedActive
after first composition? Because that sounds weirdMehmet Peker
09/10/2020, 5:44 PMandev
09/10/2020, 6:10 PMandev
09/10/2020, 6:10 PMlouiscad
09/10/2020, 11:41 PMColton Idle
09/11/2020, 5:19 AMcomposeOptions {
kotlinCompilerExtensionVersion MyVersions.compose_version
kotlinCompilerVersion '1.4.0' <====== This number
}
Rafal
09/11/2020, 8:16 AMIcons.Outlined.MailOutline
) in the IDE?Mehmet Peker
09/11/2020, 9:28 AMRafal
09/11/2020, 9:35 AMText
have a way to all caps text or do I need to use String.toUpperCase()
method?Julius Marozas
09/11/2020, 12:06 PMFabPosition.End
to FabPosition.Center
?Robert Menke
09/11/2020, 2:46 PMviewModel
function would be compatible with Hilt’s system, which was my main mental hurdle.
The following works just fine as far as I know. Are there any caveats to using this approach? Will this work fine for more complex scenarios?
@AndroidEntryPoint
class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Counter()
}
}
}
}
}
@Composable
fun Counter() {
val viewModel = viewModel<CounterViewModel>()
val state by viewModel.counter.observeAsState(0)
Column(
modifier = Modifier
.clickable(onClick = viewModel::increment)
.padding(all = 36.dp)
) {
Text(text = "Counter $state")
}
}
@ActivityScoped
class CounterViewModel @ViewModelInject constructor(): ViewModel() {
private var _counter: MutableLiveData<Int> = MutableLiveData(1)
val counter: LiveData<Int> = _counter
fun increment() {
_counter.value = _counter.value?.plus(1)
}
}
Arpan Sarkar
09/11/2020, 2:48 PMrepeatable { }
is there any way to have a callback when the animation is repeated?Guy Bieber
09/11/2020, 4:38 PMGuy Bieber
09/11/2020, 4:55 PMDaniele B
09/11/2020, 5:28 PMchris
09/11/2020, 5:50 PMAndroidView
based on the theme that is wrapping it? I'm using an AndroidView
so that I can use an ImageView
because I'm being passed a @DrawableRes
and I don't know if it will be a vector or a drawable.zoha131
09/11/2020, 9:09 PMArtem Kopan
09/12/2020, 5:56 AMVenky
09/12/2020, 10:43 AMNat Strangerweather
09/12/2020, 10:59 AMColumn(Modifier.fillMaxHeight()) {}
Why are the bottom squares no reaching the bottom of the screen? I have not put any padding.Nat Strangerweather
09/12/2020, 1:52 PMval boxModifier = Modifier
.fillMaxSize() or .fillMaxHeight()
.weight(1f)
while making sure that the box remains square, so basically, fill the maximum size/height as long as you are square? At the moment I have rectangles which is not looking great...Ian Arbuckle
09/12/2020, 2:03 PMe: java.lang.AssertionError: Unbound symbols not allowed
My dependency versions:
compose: 1.0.0-alpha02
kotlin: 1.4.10
android gradle plugin: 4.2.0.alpha10Halil Ozercan
09/12/2020, 3:04 PMrememberDismissState
doesn't receive vararg inputs: Any?
kind of anchor to reset the state if some of the dependencies change? This certainly proved a challenge when I wanted to use SwipeToDismiss
on list items. Because Lazy APIs reuse the same composable with different data, dismissState has to reset everytime the data changes.manueldidonna
09/12/2020, 4:18 PM@Stable
@Composable
fun <I, O> activityResultLauncher(
contractKey: String,
contract: ActivityResultContract<I, O>,
activityResultCallback: ActivityResultCallback<O>,
): ActivityResultLauncher<I> {
val lifecycleOwner = LifecycleOwnerAmbient.current
val registry = ActivityResultRegistryAmbient.current
val launcher = remember(contract, registry, contractKey) {
registry.register(contractKey, lifecycleOwner, contract, activityResultCallback)
}
onDispose {
launcher.unregister()
}
return launcher
}
@Composable
fun ImportSaveDataFromFile(onImport: (SaveData?) -> Unit) {
val context = ContextAmbient.current
var launchActivity by savedInstanceState { false }
val activityLauncher = activityResultLauncher("ImportSaveData", OpenDocumentContract) { uri: Uri? ->
onImport(createSaveData(uri, context))
}
if (launchActivity) {
launchActivity = false
activityLauncher.launch(arrayOf("*/*"))
}
Surface(modifier = Modifier.fillMaxSize()) {
Button(
modifier = Modifier.fillMaxSize().wrapContentSize(Alignment.Center),
onClick = { launchActivity = true }
) {
Text(text = "IMPORT SAVE DATA")
}
}
}
Sourabh Rawat
09/12/2020, 5:46 PMvipulasri
09/12/2020, 8:44 PMefemoney
09/13/2020, 2:57 AMContaner(val painters: List<Painter>): Painter {
override val intrinsicSize = Size(
painters.maxOf { it.width },
painters.sumBy { it.heightRespectingAspectRatio }
)
override fun DrawScope.onDraw() {
var offset = Offset.Zero
painters.fastForEach {
it.??? // :( not sure what to place here, I dont have access to the draw method of the individual painters, how do I tell the painter to draw into the containers canvas
}
}
}
The end goal, if its clear from the Size
calculation, is to create a painter that will place each individual painter, in a vertical column, kinda like stitching images together vertically.
I want to then be able to run transformations on the container painter (scale, pan etc) driven by gestures.efemoney
09/13/2020, 3:20 AMView
system I think it’ll be something like
painters.forEach {
canvas.withTranslate(offset.x, offset.y) {
it.draw(canvas)
}
offset.y += it.heightRespectingAspectRatio
}
Not sure the equivalent in compose