Last active
November 2, 2024 23:02
-
-
Save cbruegg/e954313c92c7fa835fe1c2ad70699876 to your computer and use it in GitHub Desktop.
Compose 1.6/1.7 Compatibility Layer
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
plugins { | |
// ... | |
} | |
android { | |
// ... | |
} | |
dependencies { | |
implementation(project(":compose-compat-on17")) | |
implementation("androidx.compose.material3:material3:1.2.1") // Compose 1.6 | |
} |
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
package composecompaton16 | |
import composecompaton17.runningOnCompose16 | |
// omitted androidx imports | |
@Composable | |
@ExperimentalMaterial3Api | |
fun ModalBottomSheetCompat( | |
contentWindowInsets: @Composable () -> WindowInsets = { BottomSheetDefaults.windowInsets }, | |
// ... | |
) { | |
if (runningOnCompose16) { | |
androidx.compose.material3.ModalBottomSheet( | |
// Obtain WindowInsets by just calling contentWindowInsets for its return value | |
windowInsets = contentWindowInsets(), | |
// ... | |
) | |
} else { | |
// We're on Compose 1.7 or higher -> Delegate to the compose-compat-on17 module | |
composecompaton17.ModalBottomSheetCompat( | |
contentWindowInsets = contentWindowInsets, | |
// ... | |
) | |
} | |
} |
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
plugins { | |
// ... | |
} | |
android { | |
// ... | |
} | |
dependencies { | |
compileOnly("androidx.compose.material3:material3:1.3.0") // Compose 1.7 | |
} |
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
package composecompaton17 | |
// omitted androidx imports | |
@Composable | |
@ExperimentalMaterial3Api | |
fun ModalBottomSheetCompat( | |
contentWindowInsets: @Composable () -> WindowInsets = { BottomSheetDefaults.windowInsets }, | |
// ... | |
) { | |
// In this module the call resolves successfully! | |
androidx.compose.material3.ModalBottomSheet( | |
contentWindowInsets = contentWindowInsets(), | |
// ... | |
) | |
} |
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
package composecompaton17 | |
val runningOnCompose16: Boolean = | |
try { | |
androidx.compose.material3.ripple(color = Color.Red) | |
false | |
} catch (e: LinkageError) { | |
true | |
} |
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
plugins { | |
// ... | |
} | |
android { | |
// ... | |
} | |
dependencies { | |
implementation(project(":compose-compat-on16")) | |
// Other Compose 1.6 dependencies here | |
} |
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
import composecompaton16.ModalBottomSheetCompat | |
// other imports omitted | |
@Composable | |
@OptIn(ExperimentalMaterial3Api::class) | |
fun MyAwesomeSdkFeature() { | |
ModalBottomSheetCompat( | |
contentWindowInsets = { /* ... */ } | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment