Skip to content

PlAnimateRotate

Content turning about a point. Two angles rather than one, which is what lets a single component cover both a quarter turn into place and a spin that never lands.

React
tsx
import { PlAnimateRotate } from 'plass-ui';

<PlAnimateRotate from={0} to={360} duration={2400} easing="linear" repeat="infinite" fade={false}>
  <PlIcon icon={<RefreshGlyph />} label="Syncing" />
</PlAnimateRotate>;
dart
import 'package:plass_ui/plass_ui.dart';

const PlAnimateRotate(
  from: 0,
  to: 360,
  duration: Duration(milliseconds: 2400),
  curve: Curves.linear,
  repeat: null,
  fade: false,
  child: PlIcon(icon: RefreshGlyph()),
);

Props

PropTypeDefaultDescription
mode'in' | 'out''in'Whether the content turns into place or out of it
fromnumber-180The angle it starts at, in degrees. Negative is anticlockwise
tonumber0The angle it ends at, in degrees. Together with from this is what makes one component cover both a turn into place and an endless spin: from={0} to={360} repeat="infinite"
originstring'center'Which point it turns about — any CSS transform-origin
fadebooleantrueFades in as it turns. Turn it off for a continuous spin, where a repeating fade would read as flickering
durationsharednumber440How long one run takes, in milliseconds. A number, never a CSS string
delaysharednumber0How long before it starts, in milliseconds
easingsharedstringthe house curveThe easing curve, written the way CSS writes it
repeatsharednumber | 'infinite'1How many times it runs. 'infinite' rather than Infinity, because that word is what reaches CSS
alternatesharedbooleanfalseRuns every other pass backwards, so a repeat returns instead of jumping
pausedsharedbooleanfalseHolds the animation where it is
triggershared'mount' | 'visible' | 'hover' | 'manual''mount'What starts it: mount as soon as it is on the page, visible when it is scrolled into view, hover while the pointer or focus is on it, manual only when play says so
playsharedbooleanRuns it when trigger is manual. Each false → true starts it over
oncesharedbooleantrueWith trigger="visible", whether it runs only the first time. Off, it runs again every time the element comes back into view
thresholdsharednumber0.2With trigger="visible", how much of the element has to be on screen before it counts as visible, from 0 to 1
timelineshared'auto' | 'view''auto'What advances the animation: the clock, or the reader's scroll position. view ignores duration, delay, repeat and trigger, and runs against range instead
rangesharedstring'entry 0% cover 45%'As CSS writes an animation-range. Only read when timeline is view
staggersharednumber0Milliseconds added to each child's delay. 0 plays the box itself; anything else moves the effect onto the children and takes it off the box
durationStepsharednumber0Milliseconds added to each child's duration. Negative is allowed; floored at 0
reversesharedbooleanfalseRuns the set from the last child to the first. Only the order turns round; each child still plays forwards
renderReactElement | (props, state) => ReactElementRenders something other than a <div>
PropTypeDefaultDescription
modePlassAnimateModePlassAnimateMode.enterWhether the content turns into place or out of it. enter/exit rather than in/out, because in is a reserved word in Dart
fromdouble-180The angle it starts at, in degrees rather than radians: the framework counts in radians and the design language counts in degrees
todouble0The angle it ends at, in degrees. Together with from this is what makes one component cover both a turn into place and an endless spin: from={0} to={360} repeat="infinite"
originAlignmentAlignment.centerWhich point it turns about — any CSS transform-origin
fadebooltrueFades in as it turns. Turn it off for a continuous spin, where a repeating fade would read as flickering
durationsharedDurationDuration(milliseconds: 440)How long one run takes, in milliseconds. A number, never a CSS string
delaysharedDurationDuration.zeroHow long before it starts, in milliseconds
curvesharedCurve?the house curveThe easing curve, written the way CSS writes it
repeatsharedint?1How many times it runs. null is what never stops: there is no 'infinite' to write, and -1 would be a sentinel a caller has to look up
alternatesharedboolfalseRuns every other pass backwards, so a repeat returns instead of jumping
pausedsharedboolfalseHolds the animation where it is
triggersharedPlassAnimateTriggerPlassAnimateTrigger.mountWhat starts it: mount as soon as it is on the page, visible when it is scrolled into view, hover while the pointer or focus is on it, manual only when play says so
playsharedboolfalseRuns it when trigger is manual. Each false → true starts it over
oncesharedbooltrueWith trigger="visible", whether it runs only the first time. Off, it runs again every time the element comes back into view
thresholdshareddouble0.2With trigger="visible", how much of the element has to be on screen before it counts as visible, from 0 to 1
child * WidgetWhat turns

Every native <div> attribute passes straight through, and render swaps the element for another one.

from and to are degrees, not radians. The framework counts in radians and the design language counts in degrees — every gradient in the package is at 135° — so the conversion happens inside the widget, once, rather than at every call site. origin is an Alignment.

The ten shared settings — duration, delay, easing, repeat, alternate, paused, trigger, play, once, threshold — are the same on every PlAnimate* component. The four trigger values are shown on the PlAnimateFade page. timeline="view" and range are there too, and hand the effect to the reader's scroll position instead of the clock.

Three more move the effect off the box and onto the things inside it: stagger holds each child back by its position, durationStep gives each one a longer or shorter run than the last, and reverse starts from the end of the set. They are on all six single-keyframe effects and are shown on the PlAnimateFade page.

Examples

from and to

from alone is an arrival: something swings into place and stops. from and to together with repeat="infinite" and easing="linear" is a spin that never lands, which is what a badge, a loading mark or a decorative glyph wants. Turn fade off for the second one — a fade that repeats reads as flickering.

React

origin

Any CSS transform-origin. Turning about a corner is a hinge rather than a wheel, and it is what a flag, a tag or a card being dealt onto a pile wants.

React

Accessibility

  • Under prefers-reduced-motion the animation is dropped entirely and the content is simply there. That is right for an arrival and worth thinking about for a spin: if the turning is what says something is happening, use PlProgressCircular instead, which slows rather than stopping.
  • Not for text. A rotated word is resampled along its whole length. Rotation is the one movement the design language allows on a glyph without argument — a chevron is turned rather than redrawn all over the library — and that is the shape of thing it is for.
  • Something that turns forever in the corner of a page somebody is reading is the one kind of motion the rest of this library refuses. Give it a reason.
  • When the platform has animations turned off (MediaQuery.disableAnimations) the effect is dropped entirely and the content is simply there. That is right for an arrival and worth thinking about for a spin: if the turning is what says something is happening, use PlProgressCircular instead, which slows rather than stopping.
  • Not for text. A rotated word is resampled along its whole length.
  • Something that turns forever in the corner of a screen somebody is reading is the one kind of motion the rest of this package refuses. Give it a reason.

Differences from the React build

ReactFlutterWhy
from, to in degreesdouble degrees, converted insideThe framework counts in radians; the design language counts in degrees, and the conversion belongs in one place.
origin as a CSS transform-origin stringAlignmentThe framework already has the type.
easing="linear"curve: Curves.linearDart's own name for the same curve.
renderFlutter has no polymorphic element.
duration, delay in millisecondsDurationThe framework already has the type.
easing as a CSS stringcurve, a CurveDart's own name for the same thing.
repeat: number | 'infinite'int?, null never stopsThere is no 'infinite' to write, and -1 would be a sentinel a caller has to look up.
trigger="visible" via IntersectionObserverwatches the nearest ScrollableThere is no observer here; with no scrollable above it there is nothing to watch, so it runs.
prefers-reduced-motionMediaQuery.disableAnimationsThe platform's own signal.
stagger, durationStep, reverseThe React build writes the effect onto the children themselves, so the caller's own layout is untouched. Flutter has no stylesheet to lay a set out with, so a staggered effect would have to own the row or the column as well — which is what PlAnimateAppear is, and six more of it would be six more of it.
timeline="view"animation-timeline is a CSS property with no counterpart here. A scroll-linked effect in Flutter is an AnimationController driven from a ScrollPosition, which is an application's own wiring rather than something a widget takes as a prop.
className, styleThere is no class list and no style attribute to pass through.

Released under the MIT License