import * as Animation from "@effect/ui-native/kit/Animation" import * as LayoutAnimation from "@effect/ui-native/kit/LayoutAnimation" import { RefreshControl } from "@effect/ui-native/kit/RefreshControl" import * as Native from "@effect/ui-native/Native" import { identity, pipe } from "effect/Function" import * as Schema from "effect/Schema" import * as Renderer from "effect/ui/Renderer" import * as UiSchema from "effect/ui/UiSchema" import { assert, describe, it } from "vitest" import * as FakeAnimated from "./utils/FakeAnimated.ts" import * as FakeFabric from "./utils/FakeFabric.ts" // Native's value reports, as the device sends them. const reports = new Set<(payload: unknown) => void>() const animated = FakeAnimated.make((event, payload) => { if (event === "onAnimatedValueUpdate") { for (const f of reports) f(payload) } }) // Mounts on a device with the native driver. const mount = ( mount: Parameters>[0], os = "android" ) => FakeFabric.mount(mount, { os, module: (name) => name === "NativeAnimatedModule" ? animated.module : undefined, on: (event, f) => { if (event !== "onAnimatedValueUpdate") return () => {} reports.add(f) return () => reports.delete(f) } }) const Sticky = Native.component({ name: "Sticky", model: Schema.Struct({ shown: Schema.Boolean, horizontal: Schema.Boolean }), message: UiSchema.TaggedEnum({ Flip: {}, Hide: {} }) }).make({ init: () => ({ shown: true, horizontal: false }), update: { Flip: ($) => $.evolve({ horizontal: (h) => !h }), Hide: ($) => $.evolve({ shown: () => false }) }, view: (h, model) => { const list = h.id("list") const y = Animation.scroll(list, "y") return h.view( model.shown && pipe( h.view.style({ height: 80 }), Animation.style({ transform: [{ translateY: Animation.interpolate(y, [0, 80], [0, -80], "clamp") }] }) ), model.shown && pipe(h.scroll.horizontal(model.horizontal), Animation.source(list)) .children( pipe( h.view.style({ height: 400 }), Animation.style({ opacity: Animation.interpolate(y, [0, 200], [1, 0], "clamp") }) ) ), h.view.style({ width: 1 }) ) } }) const Fade = Native.component({ name: "Fade", model: Schema.Struct({ open: Schema.Boolean, ended: Schema.Number }), message: UiSchema.TaggedEnum({ Toggled: {}, Ended: {} }) }).make({ init: () => ({ open: true, ended: 0 }), update: { Toggled: ($) => $.evolve({ open: (open) => !open }), Ended: ($) => $.evolve({ ended: (n) => n + 1 }) }, view: (h, model) => h.view( pipe( h.view.style({ height: 10 }).on("animationEnd", { _tag: "Ended" }), Animation.style( { opacity: model.open ? 1 : 0, transform: model.open ? [] : [{ scale: 0.5 }] }, model.open ? Animation.timing({ duration: 100 }) : Animation.immediate, { opacity: 0 } ) ), pipe(h.text("ended " + model.ended), Animation.style({})) ) }) let boxName = "" const Box = Native.component({ name: "Box", model: Schema.Struct({ ended: Schema.Number, follow: Schema.Boolean }), message: UiSchema.TaggedEnum({ Ended: {}, Follow: {} }) }).make({ init: () => ({ ended: 0, follow: false }), update: { Ended: ($) => $.evolve({ ended: (n) => n + 1 }), Follow: ($) => $.evolve({ follow: () => true }) }, view: (h, model) => h.view( pipe( h.view.style({ height: 10 }).on("animationEnd", { _tag: "Ended" }), Animation.named(boxName = h.id("box")), Animation.style({ opacity: model.follow ? Animation.add(Animation.scroll("l", "y"), 1) : 1 }) ), h.text("ended " + model.ended) ) }) const makeBox = (style: Animation.Style) => { let name = "" const Box = Native.component({ name: "Box", model: Schema.Null, message: Schema.Never }).make({ init: () => null, update: ($) => $.model, view: (h) => h.view( pipe( h.view.style({ height: 10 }), Animation.named(name = h.id("box")), Animation.style(style) ) ) }) return { Box, name: () => name } } const Follow = Native.component({ name: "Follow", model: Schema.Struct({ axis: Schema.Literals(["x", "y"]) }), message: UiSchema.TaggedEnum({ Switched: {} }) }).make({ init: () => ({ axis: "y" as const }), update: { Switched: ($) => $.evolve({ axis: (axis) => axis === "y" ? "x" : "y" }) }, view: (h, model) => { const list = h.id("list") const offset = Animation.scroll(list, model.axis) return h.view( pipe( h.view.style({ height: 80 }), Animation.style( { opacity: 1, transform: [{ translateY: Animation.interpolate(offset, [0, 100], [0, -100]) }] }, Animation.timing({ duration: 100 }), { opacity: 0 } ) ), pipe(h.scroll, Animation.source(list)) ) } }) const List = Native.component({ name: "List", model: Schema.Struct({ rows: Schema.Number, tick: Schema.Number }), message: UiSchema.TaggedEnum({ Added: {}, Ticked: {} }) }).make({ init: () => ({ rows: 1, tick: 0 }), update: { Added: ($) => $.evolve({ rows: (n) => n + 1 }).viewTransition([LayoutAnimation.spring]), // Renders nothing new, so nothing is committed or animated. Ticked: ($) => $.evolve({ tick: (n) => n + 1 }).viewTransition([LayoutAnimation.spring]) }, view: (h, model) => h.view( Array.from({ length: model.rows }, (_, i) => h.view.key(String(i)).style({ height: 20 })) ) }) const Pull = Native.component({ name: "Pull", model: Schema.Struct({ refreshable: Schema.Boolean }), message: UiSchema.TaggedEnum({ Toggled: {} }) }).make({ init: () => ({ refreshable: true }), update: { Toggled: ($) => $.evolve({ refreshable: (on) => !on }) }, view: (h, model) => { const list = h.id("list") return h.view( pipe( h.view.style({ height: 80 }), Animation.style({ opacity: Animation.interpolate( Animation.scroll(list, "y"), [0, 100], [1, 0] ) }) ), pipe( h.scroll, Animation.source(list), Animation.style({ opacity: 0.5, transform: [{ translateY: 20 }] }) ).children(model.refreshable && RefreshControl(h)) ) } }) const Headers = Native.component({ name: "Headers", model: Schema.Struct({ sticky: Schema.Boolean, hiddenOnScroll: Schema.Boolean, inverted: Schema.Boolean, inset: Schema.Number, presses: Schema.Number }), message: UiSchema.TaggedEnum({ Set: { sticky: Schema.Boolean, hiddenOnScroll: Schema.Boolean, inverted: Schema.Boolean }, Inset: { top: Schema.Number }, Pressed: {} }) }).make({ init: () => ({ sticky: true, hiddenOnScroll: false, inverted: false, inset: 0, presses: 0 }), update: { Set: ($, options) => $.evolve({ ...options }), Inset: ($, { top }) => $.evolve({ inset: () => top }), Pressed: ($) => $.evolve({ presses: (n) => n + 1 }) }, view: (h, model) => h.scroll.prop("contentInset", { top: model.inset }).pipe( model.sticky ? Animation.stickyHeaders([0, 2], { hiddenOnScroll: model.hiddenOnScroll, inverted: model.inverted }) : identity ).children( // Not a child native counts. RefreshControl(h), h.view.style({ height: 50, zIndex: 3, transform: [{ scale: model.presses > 1 ? 3 : 2 }] }).on("press", { _tag: "Pressed" }).children( h.text("A " + model.presses) ), h.view.style({ height: 300 }), h.view.style({ height: 40 }).children(h.text("B")), h.view.style({ height: 600 }) ) }) // A header that is a scroll view with a header of its own. const Nested = Native.component({ name: "Nested", model: Schema.Struct({ inner: Schema.Boolean }), message: UiSchema.TaggedEnum({ Flip: {} }) }).make({ init: () => ({ inner: true }), update: { Flip: ($) => $.evolve({ inner: (inner) => !inner }) }, view: (h, model) => h.scroll.pipe(Animation.stickyHeaders([0])).children( h.scroll.style({ height: 50, zIndex: 3 }).pipe( model.inner ? Animation.stickyHeaders([0]) : identity ).children(h.view.style({ height: 20 })), h.view.style({ height: 600 }) ) }) const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)) const headers = async (os: string) => { const mounted = await mount( (root) => Renderer.mount(Headers, {}, root), os ) const { fabric, find } = mounted const a = () => find((n) => n.props.height === 50) const b = () => find((n) => n.props.height === 40) const scroller = () => find(FakeFabric.byName("RCTScrollView")) const content = () => find(FakeFabric.byName("RCTScrollContentView")) // Where native lays them out, inside the content view at y 10. const place = (ya: number, yb: number) => { fabric.place(scroller(), [0, 0, 390, 500]) fabric.place(content(), [0, 10, 390, 1000]) fabric.place(a(), [0, 10 + ya, 390, 50]) fabric.place(b(), [0, 10 + yb, 390, 40]) } const shown = (n: { readonly tag: number }) => (animated.view(n.tag)?.transform as any)?.[0].translateY const scroll = (y: number) => { animated.scroll(scroller().tag, { y }) fabric.emit(scroller(), "topScroll", { contentOffset: { y } }) } return { ...mounted, a, b, scroller, place, shown, scroll } } // Like React Native's, the fake animated module is shared by every surface, // so tests that count its nodes run one at a time. const Panel = Native.component({ name: "Panel", model: Schema.Struct({ hidden: Schema.Boolean }), message: UiSchema.TaggedEnum({ Toggled: {} }) }).make({ init: () => ({ hidden: true }), update: { Toggled: ($) => $.evolve({ hidden: (hidden) => !hidden }) }, view: (h, model) => { const panel = h.view.style({ height: 10 }) return h.view( model.hidden ? pipe(panel, Animation.style({ opacity: 0 })) : panel ) } }) describe("Animation", { concurrent: false }, () => { it("shows the targets without a native driver, and clears them when the element stops animating", async () => { const { find, root, settle } = await FakeFabric.mount((root) => Renderer.mount(Panel, {}, root)) const panel = () => find((n) => n.props.height === 10) assert.strictEqual(panel().props.opacity, 0) root.send({ _tag: "Toggled" }) await settle() assert.isUndefined(panel().props.opacity) }) const both = { opacity: 0.5, transform: [{ translateX: 40 }, { scale: 2 }] } it.each<[Animation.Style, Animation.Style, object]>([ [{ opacity: 1 }, both, { opacity: 0.5 }], [{ transform: [{ translateX: 0 }] }, both, { transform: [{ translateX: 40 }] }], // A value from an expression isn't a target. [{ opacity: Animation.scroll("list", "y") }, { opacity: 0.75 }, { opacity: 0 }], [{ transform: [{ translateX: 0, scale: 1 }] }, { transform: [{ scale: 2 }] }, { transform: [{ translateX: 0 }, { scale: 2 }] }] ])( "sets only what the element animates without a native driver: %j", async (style, set, shown) => { const { Box, name } = makeBox(style) const { close, find, settle } = await FakeFabric.mount((root) => Renderer.mount(Box, {}, root)) const box = () => find((n) => n.props.height === 10) Animation.set(name(), set) await settle() assert.deepStrictEqual( { opacity: box().props.opacity, transform: box().props.transform }, { opacity: undefined, transform: undefined, ...shown } ) await close() } ) it("keeps what set shows without a native driver until a render changes the target", async () => { const { close, find, printed, root, settle } = await FakeFabric.mount(( root ) => Renderer.mount(Box, {}, root)) const opacity = () => find((n) => n.props.height === 10).props.opacity Animation.set(boxName, { opacity: 0.25 }) root.send({ _tag: "Ended" }) await settle() assert.include(printed(), "ended 1") assert.strictEqual(opacity(), 0.25) // The transition sets the target to 0.5. Its end event triggers a render // targeting 1, which fires a second end event. Animation.set(boxName, { opacity: 0.5 }, Animation.immediate) await settle() assert.include(printed(), "ended 3") assert.strictEqual(opacity(), 1) // The expression replaces the numeric target but still resolves to 1. Animation.set(boxName, { opacity: 0.25 }) root.send({ _tag: "Follow" }) await settle() assert.strictEqual(opacity(), 1) await close() }) it("holds a step's lower output at its repeated knot and the upper above it, as React Native", async () => { const y = Animation.scroll("list", "y") const { Box } = makeBox({ opacity: Animation.interpolate(y, [0, 0, 100], [0, 0.5, 1], "clamp"), transform: [{ translateX: Animation.interpolate(y, [-100, -10, -10], [0, 10, 20]) }] }) const { close, find } = await FakeFabric.mount((root) => Renderer.mount(Box, {}, root)) const box = find((n) => n.props.height === 10) assert.deepStrictEqual( { opacity: box.props.opacity, transform: box.props.transform }, { opacity: 0, transform: [{ translateX: 20 }] } ) await close() }) it("drives a sticky header from scroll events, across recreated views, until removed", async () => { const before = { nodes: animated.nodes(), events: animated.events() } const { close, find, root, settle } = await mount((root) => Renderer.mount(Sticky, {}, root)) const header = () => find((n) => n.props.height === 80) const hero = () => find((n) => n.props.height === 400) const scroller = () => find((n) => n.viewName.endsWith("ScrollView")) // The first frame shows each expression at offset 0. assert.deepStrictEqual(header().props.transform, [{ translateY: 0 }]) assert.strictEqual(header().props.collapsable, false) assert.strictEqual(hero().props.opacity, 1) animated.scroll(scroller().tag, { y: 40 }) assert.deepStrictEqual(animated.view(header().tag), { transform: [{ translateY: -40 }] }) assert.deepStrictEqual(animated.view(hero().tag), { opacity: 0.8 }) // A horizontal scroll view on Android is another native view, so it // and the hero inside it get new tags. const old = { scroller: scroller().tag, hero: hero().tag } root.send({ _tag: "Flip" }) await settle() assert.notStrictEqual(scroller().tag, old.scroller) assert.notStrictEqual(hero().tag, old.hero) animated.scroll(old.scroller, { y: 200 }) assert.deepStrictEqual(animated.view(hero().tag), { opacity: 0.8 }) animated.scroll(scroller().tag, { y: 200 }) assert.deepStrictEqual(animated.view(header().tag), { transform: [{ translateY: -80 }] }) assert.deepStrictEqual(animated.view(hero().tag), { opacity: 0 }) root.send({ _tag: "Hide" }) await settle() assert.deepStrictEqual( { nodes: animated.nodes(), events: animated.events() }, before ) // The renderer reused the header's node. Native keeps the driver's last // values on a view, so the node gets a new one. const reused = find((n) => n.props.width === 1) assert.isUndefined(reused.props.transform) assert.isUndefined(animated.view(reused.tag)) await close() }) it("drives scroll values from onScroll on macOS, whose native events miss them", async () => { animated.ios(true) try { const { close, fabric, find } = await mount( (root) => Renderer.mount(Sticky, {}, root), "macos" ) const header = () => find((n) => n.props.height === 80) const scroller = () => find((n) => n.viewName.endsWith("ScrollView")) fabric.emit(scroller(), "topScroll", { contentOffset: { x: 0, y: 40 } }) assert.deepStrictEqual(animated.view(header().tag), { transform: [{ translateY: -40 }] }) await close() } finally { animated.ios(false) } }) for (const os of ["ios", "android"]) { it(`docks sticky headers on the native driver, one pushing the other, on ${os}`, async () => { animated.ios(os === "ios") const before = { nodes: animated.nodes(), events: animated.events() } try { const t = await headers(os) const rows = t.find((n) => n.props.height === 300) assert.strictEqual(t.a().props.zIndex, 10) assert.isUndefined(rows.props.zIndex) // Not laid out yet: the headers scroll with the rows. t.scroll(100) assert.strictEqual(t.shown(t.a()), 0) t.place(0, 350) t.root.send({ _tag: "Pressed" }) await t.settle() assert.strictEqual(t.shown(t.a()), 100) assert.strictEqual(t.shown(t.b()), 0) // B pushes A up as it reaches it. t.scroll(320) assert.strictEqual(t.shown(t.a()), 300) // Native moves B up without a commit, and reports its layout: B // docks, pushing A further. assert.strictEqual(t.b().props.onLayout, true) t.place(0, 200) t.fabric.emit(t.b(), "topLayout", {}) assert.strictEqual(t.shown(t.a()), 150) assert.strictEqual(t.shown(t.b()), 120) // Once the scroll pauses, Fabric gets where they are shown, which // JS may not have seen. t.scroll(100) animated.scroll(t.scroller().tag, { y: 120 }) await sleep(100) assert.deepStrictEqual(t.a().props.transform, [{ translateY: 120 }]) // Its own style changes, but the header keeps its own. t.root.send({ _tag: "Pressed" }) await t.settle() assert.strictEqual(t.a().props.zIndex, 10) assert.deepStrictEqual(t.a().props.transform, [{ translateY: 120 }]) const sticky = async (sticky: boolean) => { t.root.send({ _tag: "Set", sticky, hiddenOnScroll: false, inverted: false }) await t.settle() } await sticky(false) // Its own style shows again, as it changed while it was a header, // and the driver no longer moves it. assert.strictEqual(t.a().props.zIndex, 3) assert.deepStrictEqual(t.a().props.transform, [{ scale: 3 }]) assert.isUndefined(t.a().props.onLayout) assert.isUndefined(animated.view(t.a().tag)) // Only the list's scroll value is left, still following native. assert.strictEqual(animated.nodes(), before.nodes + 1) // The new view is laid out where the old one was. t.place(0, 350) await sticky(true) // From where the list rests, which JS never saw. assert.strictEqual(t.shown(t.a()), 120) // Or from where native scrolled it while it had no headers. await sticky(false) animated.scroll(t.scroller().tag, { y: 140 }) t.place(0, 350) await sticky(true) assert.strictEqual(t.shown(t.a()), 140) t.scroll(60) assert.strictEqual(t.shown(t.a()), 60) await t.close() assert.deepStrictEqual( { nodes: animated.nodes(), events: animated.events() }, before ) } finally { animated.ios(false) } }) } it("hides a docked header while scrolling down, docks inverted headers at the bottom, and below a top inset", async () => { animated.ios(true) const before = { nodes: animated.nodes(), events: animated.events() } try { const t = await headers("ios") t.place(0, 350) const set = async (hiddenOnScroll: boolean, inverted: boolean) => { t.root.send({ _tag: "Set", sticky: true, hiddenOnScroll, inverted }) await t.settle() } await set(true, false) // Where A shows on screen: its place, scrolled, and translated. const top = (y: number) => { t.scroll(y) return t.shown(t.a()) - y } // Docked, it moves up by as much as the list scrolls down, up to its // height, and scrolling up brings it back as far. assert.strictEqual(top(30), -30) assert.strictEqual(top(100), -50) assert.strictEqual(top(80), -30) assert.strictEqual(top(20), 0) // Inverted, a header docks at the bottom of the 500 tall scroll view // once it's below it, from 150. t.scroll(0) t.place(600, 900) await set(false, true) t.scroll(200) assert.strictEqual(t.shown(t.a()), 50) // B, 300 below, pushes it at 350. t.scroll(400) assert.strictEqual(t.shown(t.a()), 200) // Below a top inset, which iOS reports as a negative offset at rest. t.place(0, 350) await set(false, false) t.root.send({ _tag: "Inset", top: 20 }) await t.settle() t.scroll(100) assert.strictEqual(t.shown(t.a()), 120) await t.close() assert.deepStrictEqual( { nodes: animated.nodes(), events: animated.events() }, before ) } finally { animated.ios(false) } }) it("keeps a scroll view a header of the one around it when its own headers go", async () => { const { close, fabric, find, root, settle } = await mount((root) => Renderer.mount(Nested, {}, root)) const inner = () => find((n) => n.props.height === 50) const outer = find(FakeFabric.byName("RCTScrollView")) const content = find(FakeFabric.byName("RCTScrollContentView")) root.send({ _tag: "Flip" }) await settle() assert.strictEqual(inner().props.zIndex, 10) assert.strictEqual(inner().props.onLayout, true) // It still follows layouts native makes. fabric.place(outer, [0, 0, 390, 500]) fabric.place(content, [0, 0, 390, 1000]) fabric.place(inner(), [0, 100, 390, 50]) fabric.emit(inner(), "topLayout", {}) animated.scroll(outer.tag, { y: 150 }) assert.deepStrictEqual(animated.view(inner().tag)?.transform, [{ translateY: 50 }]) await close() }) it("animates to each target from where the value is, and reports the end", async () => { const before = animated.nodes() const { close, find, printed, root, settle } = await mount(( root ) => Renderer.mount(Fade, {}, root)) const panel = () => find((n) => n.props.height === 10) assert.strictEqual(panel().props.opacity, 0) assert.strictEqual(animated.running(), 1) assert.isUndefined(find((n) => n.viewName === "RCTText").props.collapsable) // An immediate target interrupts the fade, and ends at once. root.send({ _tag: "Toggled" }) await settle() await settle() assert.strictEqual(animated.running(), 0) assert.deepStrictEqual(animated.view(panel().tag), { opacity: 0, transform: [{ scale: 0.5 }] }) assert.include(printed(), "ended 1") root.send({ _tag: "Toggled" }) await settle() assert.strictEqual(animated.running(), 1) animated.finish() await settle() assert.deepStrictEqual(animated.view(panel().tag), { opacity: 1 }) assert.include(printed(), "ended 2") // The end value is committed, so Fabric's shadow tree agrees. assert.strictEqual(panel().props.opacity, 1) await close() assert.strictEqual(animated.nodes(), before) }) it("commits what set shows when it reports the end", async () => { const { close, find, printed, settle } = await mount((root) => Renderer.mount(Box, {}, root)) const box = () => find((n) => n.props.height === 10) await settle() animated.finish() await settle() const ended = printed().match(/ended (\d+)/)![1] const shown = () => [animated.view(box().tag)?.opacity, box().props.opacity] Animation.set(boxName, { opacity: 0.25 }, Animation.immediate) await settle() assert.deepStrictEqual(shown(), [0.25, 0.25]) assert.include(printed(), `ended ${Number(ended) + 1}`) Animation.set( boxName, { opacity: 0.5 }, Animation.timing({ duration: 100 }) ) animated.finish() await settle() assert.deepStrictEqual(shown(), [0.5, 0.5]) assert.include(printed(), `ended ${Number(ended) + 2}`) await close() }) it("changes a graph without a mount on iOS, keeping a running fade", async () => { animated.ios(true) const before = { nodes: animated.nodes(), events: animated.events() } try { const { close, fabric, find, root, settle } = await mount( (root) => Renderer.mount(Follow, {}, root), "ios" ) const header = () => find((n) => n.props.height === 80) const scroller = () => find((n) => n.viewName.endsWith("ScrollView")) animated.progress(0.5) // Following the other axis changes nothing Fabric commits. const commits = fabric.calls.completeRoot root.send({ _tag: "Switched" }) await settle() assert.strictEqual(fabric.calls.completeRoot, commits) animated.scroll(scroller().tag, { x: 30, y: 60 }) assert.deepStrictEqual(animated.view(header().tag), { opacity: 0.5, transform: [{ translateY: -30 }] }) assert.strictEqual(animated.running(), 1) await close() assert.deepStrictEqual( { nodes: animated.nodes(), events: animated.events() }, before ) } finally { animated.ios(false) } }) it("follows each surface's own scroll view", async () => { const before = animated.nodes() const a = await mount((root) => Renderer.mount(Follow, {}, root)) const b = await mount((root) => Renderer.mount(Follow, {}, root)) const header = (s: typeof a) => s.find((n) => n.props.height === 80).tag const scroller = (s: typeof a) => s.find((n) => n.viewName.endsWith("ScrollView")).tag animated.finish() animated.scroll(scroller(a), { y: 40 }) animated.scroll(scroller(b), { y: 10 }) assert.deepStrictEqual(animated.view(header(a)), { opacity: 1, transform: [{ translateY: -40 }] }) await a.close() animated.scroll(scroller(b), { y: 20 }) assert.deepStrictEqual(animated.view(header(b)), { opacity: 1, transform: [{ translateY: -20 }] }) await b.close() assert.strictEqual(animated.nodes(), before) }) it("splits a wrapped scroll view's style between it and its refresh control, as Fabric does", async () => { const before = { nodes: animated.nodes(), events: animated.events() } const { close, find, root, settle } = await mount((root) => Renderer.mount(Pull, {}, root)) const scroller = () => find(FakeFabric.byName("RCTScrollView")) const views = () => [scroller(), find(FakeFabric.byName("AndroidSwipeRefreshLayout"))] .filter((n) => n !== undefined) // What each view shows: the driver's value, or else Fabric's. const shown = (key: string) => views().map((n) => (animated.view(n.tag)?.[key] ?? n.props[key]) as any) .filter((v) => v !== undefined) const check = () => { assert.deepStrictEqual(shown("transform"), [[{ translateY: 20 }]]) assert.deepStrictEqual(shown("opacity"), [0.5]) // Scroll events still come from the scroll view. animated.scroll(scroller().tag, { y: 50 }) assert.deepStrictEqual( animated.view(find((n) => n.props.height === 80).tag), { opacity: 0.5 } ) animated.scroll(scroller().tag, { y: 0 }) } check() root.send({ _tag: "Toggled" }) await settle() assert.strictEqual(views().length, 1) check() root.send({ _tag: "Toggled" }) await settle() assert.strictEqual(views().length, 2) check() await close() assert.deepStrictEqual( { nodes: animated.nodes(), events: animated.events() }, before ) }) }) describe("LayoutAnimation", () => { it("animates the commit of a step that asks for it and changes the tree", async () => { const { fabric, root, settle } = await mount((root) => Renderer.mount(List, {}, root)) root.send({ _tag: "Added" }) await settle() assert.deepStrictEqual(fabric.layouts, [undefined, { duration: 700, create: { type: "linear", property: "opacity" }, update: { type: "spring", springDamping: 0.4 }, delete: { type: "linear", property: "opacity" } }]) root.send({ _tag: "Ticked" }) await settle() assert.strictEqual(fabric.calls.configureNextLayoutAnimation, 1) }) })