All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.slack.circuit.foundation.internal.WithCompositionLocalProviders.kt Maven / Gradle / Ivy

The newest version!
// Copyright (C) 2024 Slack Technologies, LLC
// SPDX-License-Identifier: Apache-2.0
package com.slack.circuit.foundation.internal

import androidx.compose.runtime.Composable
import androidx.compose.runtime.InternalComposeApi
import androidx.compose.runtime.ProvidedValue
import androidx.compose.runtime.currentComposer

/**
 * A slightly more efficient version of [withCompositionLocalProvider] that only accepts a single
 * [value].
 */
@Composable
@OptIn(InternalComposeApi::class)
internal fun  withCompositionLocalProvider(
  value: ProvidedValue<*>,
  content: @Composable () -> R,
): R {
  currentComposer.startProvider(value)
  return content().also { currentComposer.endProvider() }
}

/**
 * A composable function that provides a [ProvidedValue] to the composition and returns the value
 * returned by the [content] composable. This uses internal compose APIs to start and end providers
 * around the [content] composable to avoid backward snapshot writes.
 *
 * @param values The [ProvidedValues][ProvidedValue] to provide.
 * @param content The content to provide the value to.
 */
@Composable
@OptIn(InternalComposeApi::class)
internal fun  withCompositionLocalProvider(
  vararg values: ProvidedValue<*>,
  content: @Composable () -> R,
): R {
  currentComposer.startProviders(values)
  return content().also { currentComposer.endProviders() }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy