g

    Gabriel

    1 year ago
    What's the best way to pass modifier to the sub children of a composable? I'm passing
    modifier: Modifier = Modifier
    from the parent to the child but, want to allow some control (background colour for eg) of the subchildren
    n

    Nils Druyen

    1 year ago
    You can add Modifier in your child like modifier.background(Color) example: Parent: modifier = Modifier.fillMaxSize().padding(x) then pass it to child Child: modifier = modifier.background(Color).padding(x)
    g

    Gabriel

    1 year ago
    Yeh I've got the child taking the modifier, it's the child of the child (confusing I know)
    @Composable
    fun Loading(
    	modifier: Modifier = Modifier,
    ) {
    	Card(modifier.fillMaxWidth().preferredHeight(120.dp)) {
    		Row(
    			horizontalArrangement = Arrangement.Center,
    			verticalAlignment = Alignment.CenterVertically,
    			modifier = Modifier.background(Color.Black),<------I want to be able to control this modifier when calling Loading
    		) {
    			CircularProgressIndicator(color = MaterialTheme.colors.background)
    		}
    	}
    }
    I could have modifier and childModifier, but that seem a bit ugly, wondering if there's an established pattern for it already
    n

    Nils Druyen

    1 year ago
    hmm correct seems ugly but its possible. I can't think of any other solution right now
    g

    Gabriel

    1 year ago
    I guess I could provide hard control points, spinnerBackground, spinnerColour etc
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    It's not ugly to pass in multiple modifiers, I've seen some official composables do this
    I can't remember which ones at the moment
    n

    Nils Druyen

    1 year ago
    You could also pass in a composable lambda for the children so you can define your row with progress indicator in a parent add parameter children: @Composable () -> Unit and move the child code.
    g

    Gabriel

    1 year ago
    Thanks for the ideas guys 😄