forked from cl3m/multiplatform-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
325 additions
and
22 deletions.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
...iplatform-compose/src/androidMain/kotlin/com/rouge41/kmm/compose/foundation/layout/Box.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.rouge41.kmm.compose.foundation.layout | ||
|
||
import com.rouge41.kmm.compose.runtime.Composable | ||
import com.rouge41.kmm.compose.ui.Alignment | ||
import com.rouge41.kmm.compose.ui.AlignmentVerticalAndHorizontal | ||
import com.rouge41.kmm.compose.ui.Modifier | ||
import androidx.compose.foundation.layout.Box as _Box | ||
|
||
actual typealias BoxScope = androidx.compose.foundation.layout.BoxScope | ||
|
||
@Composable | ||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") | ||
actual fun Box( | ||
modifier: Modifier = Modifier, | ||
contentAlignment: AlignmentVerticalAndHorizontal = Alignment.TopStart, | ||
content: @Composable BoxScope.() -> Unit | ||
) = _Box(modifier = modifier, contentAlignment = contentAlignment, content = content) |
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
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
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
15 changes: 15 additions & 0 deletions
15
multiplatform-compose/src/commonMain/kotlin/com/rouge41/kmm/compose/foundation/layout/Box.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.rouge41.kmm.compose.foundation.layout | ||
|
||
import com.rouge41.kmm.compose.runtime.Composable | ||
import com.rouge41.kmm.compose.ui.Alignment | ||
import com.rouge41.kmm.compose.ui.AlignmentVerticalAndHorizontal | ||
import com.rouge41.kmm.compose.ui.Modifier | ||
|
||
expect interface BoxScope | ||
|
||
@Composable | ||
expect fun Box( | ||
modifier: Modifier = Modifier, | ||
contentAlignment: AlignmentVerticalAndHorizontal = Alignment.TopStart, | ||
content: @Composable BoxScope.() -> Unit | ||
) |
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
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
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
64 changes: 64 additions & 0 deletions
64
multiplatform-compose/src/iosX64Main/kotlin/com/rouge41/kmm/compose/foundation/layout/Box.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.rouge41.kmm.compose.foundation.layout | ||
|
||
import cocoapods.YogaKit.* | ||
import com.rouge41.kmm.compose.ios.UIComposeView | ||
import com.rouge41.kmm.compose.ios.addSubview | ||
import com.rouge41.kmm.compose.runtime.Composable | ||
import com.rouge41.kmm.compose.ui.AlignmentVerticalAndHorizontal | ||
import com.rouge41.kmm.compose.ui.Modifier | ||
import com.rouge41.kmm.compose.ui.iosAlignment | ||
import com.rouge41.kmm.compose.ui.iosAlignmentVertical | ||
|
||
actual interface BoxScope | ||
class iosBoxScope : BoxScope | ||
|
||
@Composable | ||
actual fun Box( | ||
modifier: Modifier, | ||
contentAlignment: AlignmentVerticalAndHorizontal, | ||
content: @Composable BoxScope.() -> Unit | ||
) { | ||
val view = UIComposeView.createOrReuse("${content::class}") | ||
modifier.setup(view) | ||
view.configureLayoutWithBlock { layout -> | ||
when (contentAlignment) { | ||
iosAlignment.TopStart -> { | ||
layout?.alignItems = YGAlign.YGAlignFlexStart | ||
layout?.justifyContent = YGJustify.YGJustifyFlexStart | ||
} | ||
iosAlignment.TopCenter -> { | ||
layout?.alignItems = YGAlign.YGAlignFlexStart | ||
layout?.justifyContent = YGJustify.YGJustifyCenter | ||
} | ||
iosAlignment.TopEnd -> { | ||
layout?.alignItems = YGAlign.YGAlignFlexStart | ||
layout?.justifyContent = YGJustify.YGJustifyFlexEnd | ||
} | ||
iosAlignment.CenterStart -> { | ||
layout?.alignItems = YGAlign.YGAlignCenter | ||
layout?.justifyContent = YGJustify.YGJustifyFlexStart | ||
} | ||
iosAlignment.Center -> { | ||
layout?.alignItems = YGAlign.YGAlignCenter | ||
layout?.justifyContent = YGJustify.YGJustifyCenter | ||
} | ||
iosAlignment.CenterEnd -> { | ||
layout?.alignItems = YGAlign.YGAlignCenter | ||
layout?.justifyContent = YGJustify.YGJustifyFlexEnd | ||
} | ||
iosAlignment.BottomStart -> { | ||
layout?.alignItems = YGAlign.YGAlignFlexEnd | ||
layout?.justifyContent = YGJustify.YGJustifyFlexStart | ||
} | ||
iosAlignment.BottomCenter -> { | ||
layout?.alignItems = YGAlign.YGAlignFlexEnd | ||
layout?.justifyContent = YGJustify.YGJustifyCenter | ||
} | ||
iosAlignment.BottomEnd -> { | ||
layout?.alignItems = YGAlign.YGAlignFlexEnd | ||
layout?.justifyContent = YGJustify.YGJustifyFlexEnd | ||
} | ||
} | ||
} | ||
addSubview(view) { content.invoke(iosBoxScope()) } | ||
} |
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
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
Oops, something went wrong.