Lynx

Scale Feedback

Learn how to apply Main Thread-based Crispy Scale Feedback in Lynx.

Engine ≥ 3.6

Crispy's Scale Feedback slightly reduces an element while pressing to immediately convey that the input has been received. Instead of using a fixed scale, the scale is calculated from the rendered size, so small icon buttons and full-width elements respond with similar press distance.

The Lynx implementation uses ScaleFeedback and useScaleFeedback from @seed-design/lynx-react. Use the utility component when applying Self Scale to a single visual area, and use the hook when separating trigger and target or when you need to target a specific native element.

Scale Calculation Method

The actual width and height are read from the target's main-thread:bindlayoutchange and the scale is calculated using the following formula. If a target that is not yet visible is measured as 0 × 0, that value is not used, and the current size is re-read from the Main Thread at the moment of first press.

basis = max(height, width / 4, 24)
scale = (basis - 2) / basis

The meaning of reduction amount, width correction value, and minimum base length can be found in Scale Foundation.

Applying Self Scale with ScaleFeedback

When applying Self Scale to a single visual area, wrap it with ScaleFeedback. ScaleFeedback renders a native view that becomes the animation target and applies Main Thread props to it.

import { ScaleFeedback } from "@seed-design/lynx-react";

function Pressable() {
  return (
    <ScaleFeedback>
      <view>
        <text>Press me</text>
      </view>
    </ScaleFeedback>
  );
}

The wrapper uses flatten={false} to remain as the actual animation target. Lynx's flatten is an optimization that reduces rendering cost by merging elements that don't need separate render objects with their parent, so it must be disabled on elements used as refs and animation targets.

The child's ref and event props are not changed. If the child's touch event propagates to the wrapper, the child handler and Scale Feedback execute together. If you stop event propagation in the child or if the wrapper affects the layout, use useScaleFeedback to pass props directly to the exact trigger and target.

React's ScaleFeedback passes props to the child via Slot without creating a DOM wrapper, but ReactLynx's main-thread:* handlers must be statically connected to native JSX elements. Therefore, the Lynx utility does not inject Main Thread props with cloneElement() but explicitly renders a native wrapper.

Applying Self and Content Scale with useScaleFeedback

The hook returns props for the element that receives the touch and the element that actually scales down, separated.

import { mergeProps, useScaleFeedback } from "@seed-design/lynx-react";

function Pressable() {
  const { scaleFeedbackTriggerProps, scaleFeedbackTargetProps } = useScaleFeedback();

  return (
    <view {...mergeProps(scaleFeedbackTriggerProps, scaleFeedbackTargetProps)}>
      <text>Press me</text>
    </view>
  );
}
Loading Lynx example…

scaleFeedbackTargetProps includes flatten={false} so that the Main Thread ref and animation point to the actual render object. Pass the props object as is to the target.

Composing with Existing Events and Refs

When passing multiple props objects to the same element, use mergeProps(). Simple spread overwrites events and refs with the same name, but mergeProps() preserves existing behavior together.

<view
  {...mergeProps(scaleFeedbackTriggerProps, scaleFeedbackTargetProps, userProps)}
  flatten={false}
/>

Events with the same name from objects passed later are executed first, so pass user props last. Returning false or preventDefault() does not cancel the execution of other handlers. className is connected and object style is shallowly merged, with later values taking priority for normal values. undefined maintains the previous value. Keep animation target's flatten={false} even after user props.

ref and main-thread:ref each compose connections and cleanup in their own threads. Events are also composed only with exactly matching keys, so they do not change the propagation method or execution thread of bindtap, catchtap, or main-thread:bindtap. mergeProps() does not perform cross-thread passing. Connect Background logic for the same touch input with the hook's onTouchStart, onTouchEnd, and onTouchCancel.

Browser preview is for checking structure and basic interaction. Check the actual Scale Feedback behavior in Lynx Explorer.

Choosing Between Self and Content

The two approaches differ in target location, not in the formula.

ScopeTriggerTargetUsage Examples
SelfCorresponding action areaSame action areaAction Button, Reaction Button, Chip, Tab, App Bar's IconButton, Page Banner's Button·CloseButton, Input Button's ClearButton, Swipeable Menu Sheet's CloseButton
ContentItem or body action areaInternal content layerAccordion, List, Select Box, Segmented Control, Menu Item, Input Button body, actionable Page Banner, Swipeable Menu Sheet Item

Self Scale passes both props to the same element. Content Scale passes trigger props to the outer element and target props to the inner content.

const { scaleFeedbackTriggerProps, scaleFeedbackTargetProps } = useScaleFeedback();

return (
  <view {...scaleFeedbackTriggerProps}>
    <view {...scaleFeedbackTargetProps}>{children}</view>
  </view>
);

Components like Checkbox, Radio, and Switch that include a label in the Root and receive touch but only the mark should scale down also use the same pattern.

Main Thread and Background Thread

Scale Feedback divides one touch event and handles it as follows:

Execution LocationResponsibility
Main ThreadLayout measurement, touch event handling, Element.animate() execution·stopping
Background ThreadonTouchStart·onTouchEnd·onTouchCancel callback, tap and business logic

The Main Thread handler starts the scale immediately and passes only necessary callbacks via runOnBackground(). Inside a Main Thread function, do not directly use React state, network requests, or NativeModule.

When directly combining with usePressTap, pass bindtouchstart, bindtouchend, bindtouchcancel as onTouchStart, onTouchEnd, onTouchCancel. Do not register separate Main/Background handlers for the same touch event.

pressed Color Feedback

The pressed color that changes with scale starts from Lynx CSS's :active. Since Background Thread's usePressTap() doesn't wait for the className to update, color transition starts with Main Thread input even in short taps.

Components like Action Button, Chip, and Callout where trigger and color target are the same use the Self selector. Components like Accordion, Checkbox, and Radio where the target is an internal slot use the :active selector of the enabled trigger to target the corresponding content class. No active selector class is generated for disabled or loading variants.

The pressed variant in the Background Thread is maintained for state-based rendering and existing fallback. Immediate visual response is handled by :active, and tap handling and React state are handled by usePressTap().

Animation and Rootage Values

Scale is executed with Element.animate() rather than writing CSS transition strings to inline style. Therefore, it does not overwrite background-color, color, or border-color transitions already declared on the target.

ValueRootage sourceCurrent Value
Duration$duration.pressed-scale150ms
Easing$timing-function.pressed-scalecubic-bezier(0, 0, 0.15, 1)

At build time, a @seed-design/lynx-css/scale-feedback runtime module is generated, and the hook uses this value on the Main Thread. Since the value is not copied to the hook, when Rootage changes, React and Lynx are updated together through the generated result.

If touchend or touchcancel occurs during a previous animation, the computed transform is read, the existing Animation is canceled, and it returns to scale(1) from the current point.

Reducing Motion

useScaleFeedback reads motion from useGlobalProps() of @lynx-js/react.

motionBehavior
"reduced"Keep scale at 1
"preferred"Apply Scale Feedback
undefined, null, unknown valuesSafely fallback to default behavior

Default behavior is also used when there is no GlobalProps object itself. If motion changes to "reduced" during press or the component becomes disabled, the target is returned to scale(1).

disabled, loading, and Nested Targets

  • Do not scale down if disabled: true.
  • States that do not accept additional input, like Loading, are also passed as disabled: true.
  • Do not apply duplicate Scale Feedback to targets inside parent elements that are already scaling down.
  • If the target uses an existing transform, create a dedicated content layer. Since the hook owns the target's transform, directly connecting it to the same node with translate·rotate will overwrite the existing transform.

API

ScaleFeedback

Prop

Type

useScaleFeedback

Prop

Type

Prop

Type

References

Table of contents