-
Notifications
You must be signed in to change notification settings - Fork 74
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
5 changed files
with
201 additions
and
7 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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
apply plugin: 'org.jetbrains.kotlin.multiplatform' | ||
|
||
redwoodBuild { | ||
publishing() | ||
} | ||
|
||
kotlin { | ||
|
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
61 changes: 61 additions & 0 deletions
61
...ylayout-dom/src/commonMain/kotlin/app/cash/redwood/lazylayout/dom/IntersectionObserver.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,61 @@ | ||
/* | ||
* Copyright (C) 2024 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.lazylayout.dom | ||
|
||
import org.w3c.dom.DOMRect | ||
import org.w3c.dom.Element | ||
import org.w3c.dom.ParentNode | ||
|
||
/** | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API | ||
*/ | ||
internal external class IntersectionObserver( | ||
callback: (entries: Array<IntersectionObserverEntry>, observer: IntersectionObserver) -> Unit, | ||
options: IntersectionObserverOptions = definedExternally, | ||
) { | ||
val root: ParentNode | ||
|
||
val rootMargin: String | ||
val thresholds: Array<Double> | ||
|
||
fun disconnect() | ||
|
||
fun observe(target: Element) | ||
|
||
fun unobserve(target: Element) | ||
} | ||
|
||
internal sealed external interface IntersectionObserverOptions { | ||
var root: ParentNode? | ||
var rootMargin: String? | ||
var threshold: Array<Double>? | ||
} | ||
|
||
internal external class IntersectionObserverEntry { | ||
val boundingClientRect: DOMRect | ||
|
||
val intersectionRatio: Double | ||
|
||
val intersectionRect: DOMRect | ||
|
||
val isIntersecting: Boolean | ||
|
||
val rootBounds: DOMRect? | ||
|
||
val target: Element | ||
|
||
val time: Double | ||
} |
44 changes: 44 additions & 0 deletions
44
redwood-lazylayout-dom/src/commonMain/kotlin/app/cash/redwood/lazylayout/dom/utils.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,44 @@ | ||
/* | ||
* Copyright (C) 2024 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.lazylayout.dom | ||
|
||
import app.cash.redwood.layout.api.Constraint | ||
import app.cash.redwood.ui.Density | ||
import app.cash.redwood.ui.Dp | ||
import kotlin.math.roundToInt | ||
import org.w3c.dom.css.CSSStyleDeclaration | ||
|
||
internal fun Dp.toPxString(): String = with(Density(1.0)) { | ||
"${toPx().roundToInt()}px" | ||
} | ||
|
||
internal fun Constraint.toCss() = when (this) { | ||
Constraint.Wrap -> "auto" | ||
Constraint.Fill -> "100%" | ||
else -> throw AssertionError() | ||
} | ||
|
||
internal var CSSStyleDeclaration.marginInlineStart: String | ||
get() = this.getPropertyValue("margin-inline-start") | ||
set(value) { | ||
this.setProperty("margin-inline-start", value) | ||
} | ||
|
||
internal var CSSStyleDeclaration.marginInlineEnd: String | ||
get() = this.getPropertyValue("margin-inline-end") | ||
set(value) { | ||
this.setProperty("margin-inline-end", value) | ||
} |