Repository navigation
Animate native views on the native driver with Animation and LayoutAnimation - #519
Merged
Merged
Conversation
Bundle sizeProduction build, gzip level 9 per chunk. Effect-only client: 26780 B gzip. Full report
|
effect-bot
force-pushed
the
agent/nelson-effect-bot/6a1d0d711132
branch
4 times, most recently
from
November 28, 2026 06:26
441edb9 to
22f0f4d
Compare
Animation drives opacity and transform on React Native's native animated driver, and LayoutAnimation animates a step's layout changes.
effect-bot
force-pushed
the
agent/nelson-effect-bot/6a1d0d711132
branch
from
November 28, 2026 06:32
22f0f4d to
4272028
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes EFF-4574
Adds native animation to
@effect/ui-nativewithout porting React Native'sAnimated. Two kit modules talk to the native side directly:AnimationdrivesopacityandtransformthroughNativeAnimatedModule. A number in the style is a target: when a render changes it, the driver animates from wherever the value is (timing,springorimmediate). An expression follows a scroll view's offset (scroll,interpolate,add,multiply,diffClamp), so a sticky header moves on the UI thread with no JS per frame.animationEndfires once every target of the element is reached.LayoutAnimationregisters configs under view transition names, so$.viewTransition([LayoutAnimation.spring])animates that step's layout changes.How the driver follows views
There's no
Mountinvolved.Animation.stylesets ananimationprop that the module registers a setter for, plus a hook that runs after every commit. After each commit the hook:Every operation of a commit goes into one
startOperationBatch/finishOperationBatchpair, so Android runs them in one frame. iOS ignores the batch and holds graph operations until the next mount, so on iOS the driver ends each batch withstopAnimationof an id that doesn't exist, which flushes the queue. Without it, a commit that changes only the graph (a header switching scroll axis) waits for an unrelated mount. The first frame showsfrom, or else the target, or else the expression at scroll offset 0, so nothing flashes before the driver connects. When an animation ends, the end values are committed so Fabric's shadow tree matches what's on screen, which keeps press hit tests right for views that moved. A change made withimmediateends at once, andanimationEndfires after the commit.Native keeps showing the driver's last
opacity/transformon a view after the driver disconnects (Android'stagToSynchronousMountProps, iOS'spropKeysManagedByAnimated), until the view is deleted. So when a mounted element stops animating a key, the driver asks the host to recreate its view with a new tag (ViewHost.recreate). A key with no values, as in{}or{ transform: [] }, is no animation for that key. Without a native driver, the view shows the targets as plain props, and clears them when the element stops animating.Both platforms bind
onScrollEndedalong withonScroll, but only Android removes it along withonScroll(RCTNativeAnimatedNodesManager.mm), so on iOS the driver removes it explicitly.On Android, a
scrollwith aRefreshControlrenders insideAndroidSwipeRefreshLayout, and the host gives the wrapper the scroll view's outer props,transformincluded. Like React Native'sAnimatedScrollView, the driver then builds one props node per view: keys the wrapper takes connect to the wrapper's view, the rest to the scroll view, and the graph is rebuilt when the wrapper comes or goes. Seeded and end values go through the host, so they land on the same views. Scroll events stay bound to the scroll view.Only
opacityandtransformare animated. Those are the two props React Native keeps the driver's value for when a later commit resends a view's props (Android'sgetAnimatedPropsMap, iOS'spropKeysManagedByAnimated). Colours, layout props androtateare left out.Host changes (paid by every app)
NativeHostlooks up props it doesn't know in a registry that kit modules fill, and runs registered hooks after each commit.viewTransitionlooks the step's types up in theLayoutAnimationregistry.configureNextLayoutAnimationis called just beforecompleteRoot, and only if the commit changes the tree, so a render with no Fabric diff leaves nothing pending in C++.Native.ViewHostgainscommitandrecreate, andViewEventsgainsanimationEnd. Commit hooks get the surface'sViewHost.Bundle size
Android release JS for
examples/native(expo export --no-bytecode, as in its README):main(e0b7cec)LayoutAnimationdemoThe no-import build contains none of
NativeAnimated*,animationSourceorstartAnimatingNode. Its only new string isconfigureNextLayoutAnimation, which comes from the host. The last row also counts the demo's own view code.Tests
test/utils/FakeAnimated.tsevaluates the node graph the way native does, and throws where native would fail or leak (a dropped node that is still connected or still feeds another, an edge to a missing node). Like native, a view keeps the driver's last values after it disconnects, and aniosmode holds graph operations until one that iOS flushes, and leavesonScrollEndedbound whenonScrollis removed, as iOS does. Dropping a node that is still bound to an event throws. The tests check what each view shows:from. Animmediatetarget interrupts it and firesanimationEndonce, and a later timing fires it again with the end value committed. An empty style creates nothing, and an empty transform clears the one shown before. Closing the surface drops every node.LayoutAnimationis configured for the commit of a step that asks for it, and not for a step that asks but changes nothing.Not verified on a device
All of this comes from reading React Native 0.88.1's sources and running the fakes above. None of it has run on hardware.
onScrollprop set (Android dispatches them anyway; iOS posts them fromRCTScrollViewComponentViewwith a default throttle of 0).NativeAnimatedTurboModulefirst, thenNativeAnimatedModule. That matches bridgeless withcxxNativeAnimatedEnabledoff, which is the default.LayoutAnimationneedsenableLayoutAnimationsOnAndroid, which is off by default in 0.88.1. Without it the layout changes at once.Notes
NativeHost.ts,internal/kinds.ts,kit/index.tsandFakeFabric.ts. Whichever PR lands second needs a small rebase.decay, loops and keyframes, colours, layout props, androtate(Fabric wants angle strings, which needs string-output interpolation). Gesture-driven animation is left for the responder work in EFF-4569.