Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contract/cli/src/vocab/card.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ option | value
time | datetime format
progress | value max start end
list | listStyle appearance virtualized refreshing scroll-start | reachstart reachend refresh
scroll | scrollTop navigationScroll keyboardDismissMode | scroll scrollend
scroll | scrollTop navigationScroll keyboardDismissMode zoomScale | scroll scrollend
dialog | closedby | cancel close

## rules
Expand Down
2 changes: 2 additions & 0 deletions contract/lower/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ pub fn attr(name: &str) -> Option<AttrTarget> {
"color-type" => AttrTarget::Prop(p("colorType")),
"scrollTop" => AttrTarget::Prop(p("scrollTop")),
"scrollLeft" => AttrTarget::Prop(p("scrollLeft")),
// UIKit's pinch zoom of a scroller's one child (iOS).
"minimumZoomScale" | "maximumZoomScale" | "zoomScale" => AttrTarget::Prop(p(name)),
"swipeContent" => AttrTarget::Prop(p("swipeContent")),
"swipeLeading" => AttrTarget::Prop(p("swipeLeading")),
"swipeTrailing" => AttrTarget::Prop(p("swipeTrailing")),
Expand Down
2 changes: 1 addition & 1 deletion docs/card.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ tags: attributes; on events. Every tag also takes CSS style attributes and colou
time: datetime format
progress: value max start end
list: listStyle appearance virtualized refreshing scroll-start; on reachstart reachend refresh
scroll: scrollTop navigationScroll keyboardDismissMode; on scroll scrollend
scroll: scrollTop navigationScroll keyboardDismissMode zoomScale; on scroll scrollend
dialog: closedby; on cancel close

parts: use X from "exact:content"; an option is none or some(…)
Expand Down
9 changes: 9 additions & 0 deletions host/apple/Sources/ExactKit/IOS/NodeExtrasIOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ final class NodeExtras {
var layoutOffset: CGPoint = .zero
/// How far its scroller's scroll moves a sticky box (LLP 1083, `Sticky.swift`).
var stickyOffset: CGPoint = .zero
/// The scale its zooming scroller draws it at, and how far that centres it (`ScrollZoomIOS.swift`).
var zoomFactor: CGFloat = 1
var zoomShift: CGPoint = .zero
/// A zooming scroller's: the view UIKit zooms, the child drawn from it, and a `zoomScale` not yet applied.
var zoomProxy: UIView?
weak var zoomed: NodeView?
var pendingZoomScale: Double?
var keyboardLift: CGFloat = 0
/// How far its surface's size stands from the laid-out size (LLP 1063).
var layoutResize: CGSize = .zero
Expand Down Expand Up @@ -302,6 +309,8 @@ extension NodeView {
var clipBox: PlainView? { get { extras?.clipBox } set { if newValue != nil || extras != nil { more.clipBox = newValue } } }
var layoutOffset: CGPoint { get { extras?.layoutOffset ?? .zero } set { if newValue != .zero || extras != nil { more.layoutOffset = newValue } } }
var stickyOffset: CGPoint { get { extras?.stickyOffset ?? .zero } set { if newValue != .zero || extras != nil { more.stickyOffset = newValue } } }
var zoomFactor: CGFloat { get { extras?.zoomFactor ?? 1 } set { if newValue != 1 || extras != nil { more.zoomFactor = newValue } } }
var zoomShift: CGPoint { get { extras?.zoomShift ?? .zero } set { if newValue != .zero || extras != nil { more.zoomShift = newValue } } }
var authoredAccentTint: UIColor? { get { extras?.authoredAccentTint } set { if newValue != nil || extras != nil { more.authoredAccentTint = newValue } } }
/// How far a keyboard toolbar rides up with the keyboard (KeyboardToolbarIOS).
var keyboardLift: CGFloat { get { extras?.keyboardLift ?? 0 } set { if newValue != 0 || extras != nil { more.keyboardLift = newValue } } }
Expand Down
6 changes: 5 additions & 1 deletion host/apple/Sources/ExactKit/IOS/NodePoolIOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ extension NodeView {
/// list's scroll, with its delegate detached while it resets.
func recycleScroll() {
guard let sv = scroll else { return }
#if os(iOS)
dropZoom()
extras?.pendingZoomScale = nil
#endif
let delegate = sv.delegate
sv.delegate = nil
sv.setContentOffset(.zero, animated: false)
Expand Down Expand Up @@ -600,7 +604,7 @@ extension NodeView {
// UIKit's setters are not free, even to the same value.
if isHidden { isHidden = false }
if alpha != 1 || boxFilter != nil { presentOpacity(1) }
translatePx = .zero; translatePercent = .zero; layoutOffset = .zero; layoutResize = .zero; endSurface(); scale = 1; rotate = 0; stopPressEase(); press = PressFeedback(); dropPressPaint()
translatePx = .zero; translatePercent = .zero; layoutOffset = .zero; zoomFactor = 1; zoomShift = .zero; layoutResize = .zero; endSurface(); scale = 1; rotate = 0; stopPressEase(); press = PressFeedback(); dropPressPaint()
if !transform.isIdentity { transform = .identity }
if !isUserInteractionEnabled { isUserInteractionEnabled = true }
// With assistive technology's runtime loaded every accessibility
Expand Down
4 changes: 4 additions & 0 deletions host/apple/Sources/ExactKit/IOS/NodeViewIOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ package final class NodeView: UIView, UITextViewDelegate, UITextFieldDelegate, U
if let raw = set["scrollLeft"], let left = Double(raw), left.isFinite { pendingScrollLeft = left }
if clear.contains("scrollTop") { pendingScrollTop = nil }
if let raw = set["scrollTop"], let top = Double(raw), top.isFinite { pendingScrollTop = top }
if let raw = set["zoomScale"], let scale = Double(raw), scale.isFinite, scale > 0 { more.pendingZoomScale = scale }
// One assignment: `props` tells the presenter of each.
var next = props
for k in clear { next.removeValue(forKey: k) }
Expand Down Expand Up @@ -1323,6 +1324,9 @@ package final class NodeView: UIView, UITextViewDelegate, UITextFieldDelegate, U
// Ending where its last edge is drawn, from this box's place on the
// pixel grid, so the furthest offset is a whole pixel and reaches it (`PixelGridIOS.swift`).
let s = presenter?.gridScale ?? 1, o = grid?.origin ?? .zero
#if os(iOS)
let content = zoomedContent
#endif
let size = CGSize(width: sv.scrollsX ? max(PixelGrid.length(content.width, from: o, vertical: false, scale: s), sv.bounds.width) : sv.bounds.width,
height: sv.scrollsY ? max(PixelGrid.length(content.height, from: o, vertical: true, scale: s), scrollFloor(sv)) : sv.bounds.height)
if sv.contentSize != size { sv.contentSize = size }
Expand Down
3 changes: 3 additions & 0 deletions host/apple/Sources/ExactKit/IOS/ScrollViewIOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ extension Presenter {
// Settle that layout before restoring or authoring an offset.
if node.groupedOwner { node.scrollView?.layoutIfNeeded() }
if !collections.owns(node.id) { node.restoreScrollPosition(authored: authored.contains { $0.isDescendant(of: node) }) }
#if os(iOS)
node.settleZoom()
#endif
if let material = node.materialView { node.sendSubviewToBack(node.glassSlot ?? material) }
}
// Every capture is restored before any authored offset lands: a
Expand Down
101 changes: 101 additions & 0 deletions host/apple/Sources/ExactKit/IOS/ScrollZoomIOS.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// UIKit's pinch zoom on a scroll container with one child
// (`minimumZoomScale`, `maximumZoomScale`, `zoomScale`). UIKit zooms a view
// of its own that it alone writes: a node's transform is the host's
// (`applyTransform`), and a view two writers transform shows whichever wrote
// last. The child is drawn from the scroller's scale through
// `hostPlacement`, so its own transform, a press and an animation compose
// with it. The child keeps its layout: its box in the scroller is its size
// times the scale, what layout put around it stays as it is, and it is
// centred while the whole is smaller than the port, as a photo is.
#if os(iOS)
import UIKit

extension NodeView {
/// The range a pinch zooms through, when the props give one.
var zoomRange: ClosedRange<CGFloat>? {
guard let low = props["minimumZoomScale"].flatMap(Double.init), let high = props["maximumZoomScale"].flatMap(Double.init),
low.isFinite, high.isFinite, low > 0, high > low else { return nil }
return CGFloat(low)...CGFloat(high)
}
/// The content extent with the zoomed child at its scale.
var zoomedContent: CGSize {
guard let e = extras, e.zoomProxy != nil, let sv = scroll, let child = e.zoomed, let size = child.grid?.drawn.size else { return content }
let grown = sv.zoomScale - 1
return CGSize(width: content.width + size.width * grown, height: content.height + size.height * grown)
}

/// After a batch: the range and the scale the props give, and the child
/// where they put it.
func settleZoom() {
guard let sv = scroll else { return }
let nodes = sv.subviews.compactMap { $0 as? NodeView }
guard let range = zoomRange, nodes.count == 1, nodes[0].grid != nil else { return dropZoom() }
let opening = extras?.zoomProxy == nil
if extras?.zoomed !== nodes[0] { dropZoom() }
if extras?.zoomProxy == nil {
let proxy = UIView()
proxy.isUserInteractionEnabled = false
sv.insertSubview(proxy, at: 0)
more.zoomProxy = proxy
more.zoomed = nodes[0]
placeZoom()
}
if sv.minimumZoomScale != range.lowerBound { sv.minimumZoomScale = range.lowerBound }
if sv.maximumZoomScale != range.upperBound { sv.maximumZoomScale = range.upperBound }
let asked = extras?.pendingZoomScale.map { CGFloat($0) }
more.pendingZoomScale = nil
if !sv.isZooming, !sv.isZoomBouncing {
let scale = min(max(asked ?? sv.zoomScale, range.lowerBound), range.upperBound)
if scale != sv.zoomScale {
let offset = sv.contentOffset
sv.zoomScale = scale
// A scroller that opens zoomed opens at its start.
if opening { sv.contentOffset = offset }
}
}
placeZoom()
}

/// The child drawn at the scroller's scale, the extent that gives, and
/// UIKit's view over where the child shows, which its next step zooms from.
func placeZoom() {
guard let sv = scroll, let e = extras, let proxy = e.zoomProxy, let child = e.zoomed, let place = child.grid?.drawn else { return }
let scale = sv.zoomScale, extent = zoomedContent
let shift = CGPoint(x: max(0, (sv.bounds.width - extent.width) / 2), y: max(0, (scrollFloor(sv) - extent.height) / 2))
if child.zoomFactor != scale || child.zoomShift != shift {
child.zoomFactor = scale; child.zoomShift = shift
child.applyTransform()
}
fitScroll()
if proxy.bounds.size != place.size { proxy.bounds.size = place.size }
let center = CGPoint(x: place.minX + shift.x + place.width * scale / 2, y: place.minY + shift.y + place.height * scale / 2)
if proxy.center != center { proxy.center = center }
}

/// No zoom any more: the child as layout placed it.
func dropZoom() {
guard let e = extras, let proxy = e.zoomProxy else { return }
if let sv = scroll {
if sv.zoomScale != 1 { sv.zoomScale = 1 }
sv.minimumZoomScale = 1; sv.maximumZoomScale = 1
}
proxy.removeFromSuperview()
e.zoomProxy = nil
if let child = e.zoomed, child.zoomFactor != 1 || child.zoomShift != .zero {
child.zoomFactor = 1; child.zoomShift = .zero
child.applyTransform()
}
e.zoomed = nil
fitScroll()
}

package func viewForZooming(in scrollView: UIScrollView) -> UIView? {
scrollView === scroll ? extras?.zoomProxy : nil
}
package func scrollViewDidZoom(_ scrollView: UIScrollView) {
guard scrollView === scroll else { return }
placeZoom()
queueScrollEvent()
}
}
#endif
6 changes: 5 additions & 1 deletion host/apple/Sources/ExactKit/PressFeedback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ extension NodeView {
/// transform: a layout transition's offset, a sticky box's scroll offset
/// (LLP 1083), a keyboard toolbar's lift and a context preview's projection.
var hostPlacement: CGAffineTransform {
CGAffineTransform(translationX: layoutOffset.x + stickyOffset.x, y: layoutOffset.y - keyboardLift + stickyOffset.y + controlRide).concatenating(contextTransform)
let placed = CGAffineTransform(translationX: layoutOffset.x + stickyOffset.x, y: layoutOffset.y - keyboardLift + stickyOffset.y + controlRide).concatenating(contextTransform)
// A zooming scroller's child, scaled from its box's top left (`ScrollZoomIOS.swift`); UIKit scales about the centre.
let zoom = zoomFactor, shift = zoomShift
guard zoom != 1 || shift != .zero else { return placed }
return placed.concatenating(CGAffineTransform(a: zoom, b: 0, c: 0, d: zoom, tx: (zoom - 1) * bounds.width / 2 + shift.x, ty: (zoom - 1) * bounds.height / 2 + shift.y))
}
/// The border box in `viewport`'s visible space as an open top-layer box
/// is told to the runner: before its own transform, which the runner
Expand Down
8 changes: 8 additions & 0 deletions host/web-js/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,14 @@ impl Em<'_> {
{
continue;
}
// Nor has UIKit's pinch zoom.
if b.kind == BindingKind::Prop
&& (b.id == PropId::MinimumZoomScale as u16
|| b.id == PropId::MaximumZoomScale as u16
|| b.id == PropId::ZoomScale as u16)
{
continue;
}
if let Some(v) = style::literal(plan, plan.code(b.expr)) {
if markdown && b.kind == BindingKind::Prop && b.id == PropId::Text as u16 {
let source = serde_json::to_string(v.as_str().unwrap_or_default()).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions host/web/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@ pub fn props_of(node: &NodeFacts<'_>) -> SortedMap<String, String> {
// Read by rt.js's image fade.
PropId::FadeDuration => "data-exact-fade",
PropId::Loading => "loading",
// UIKit's pinch zoom; a page's is the browser's.
PropId::MinimumZoomScale | PropId::MaximumZoomScale | PropId::ZoomScale => continue,
// Read by wakelock-glue.js (LLP 1125 D11).
PropId::Wakelock => "data-exact-wakelock",
// Read by orientationlock-glue.js (LLP 1133.029 D7).
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/wire/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ mod tests {
// schema. The literal makes an accidental removal of that coupling a
// test failure whenever the byte snapshot above is intentionally moved.
// Recomputed when the schema changes; the digest test prints the value.
assert_eq!(SCHEMA_DIGEST, 0xc44798a91fd796dc);
assert_eq!(SCHEMA_DIGEST, 0xb3941128c52632b8);
}

#[test]
Expand Down
17 changes: 17 additions & 0 deletions kernel/tables/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,23 @@
"name": "loading",
"kind": "str",
"_comment": "HTML's `loading` on an image, `lazy` or `eager`. Unset, the web chooses: an image a `for` repeats loads as its row comes into view, a lone one with the page. Native hosts load what a list shows and ignore it."
},
{
"id": 312,
"name": "minimumZoomScale",
"kind": "float",
"_comment": "UIKit's `minimumZoomScale` on a scroll container with one child: with `maximumZoomScale`, the range a pinch scales that child through, about the fingers. The child keeps its layout; its box in the scroller is its size times the scale, centred while smaller than the port. iOS; other hosts ignore the three."
},
{
"id": 313,
"name": "maximumZoomScale",
"kind": "float"
},
{
"id": 314,
"name": "zoomScale",
"kind": "float",
"_comment": "The scale a zooming scroll container opens at, and moves to when the value changes."
}
],
"_enums": "Wire discriminant is the 0-based index. An unknown discriminant is a typed decode rejection, never a fallback. refused: keywords the wire carries and the compiler refuses an author, because no presenter builds them (LLP 1043.000 §3 D1); `contract vocab` lists the others. No wire reads it, so it is outside the digest.",
Expand Down
Loading