Lynx ui swiper

From lynx-family/lynx-ui · View interactive version

Lynx ui swiper is an AI agent skill from the GitHub repository lynx-family/lynx-ui. `Swiper` is a high-performance, fully customizable carousel. It supports horizontal swiping, looping, auto-play, RTL, edge bounces, and both built-in and custom layouts/animations. This guide is writt

How to use this skill

Skill file

lynx-ui-swiper SKILL

Swiper is a high-performance, fully customizable carousel. It supports horizontal swiping, looping, auto-play, RTL, edge bounces, and both built-in and custom layouts/animations. This guide is written for AI code agents to generate correct, production-ready code with minimal back-and-forth.

1. Core Capabilities

2. AI Coding Guide

Minimal Usable Example

Each <Swiper> must provide data, itemWidth, and containerWidth, and render children via a function that returns a <SwiperItem>.

This example uses a 320px-wide wrapper and 300px-wide items.

import { Swiper, SwiperItem } from '@lynx-js/lynx-ui'

const data = ['red', 'green', 'blue']
const CONTAINER_WIDTH = 320

function Example() {
  return (
    <view style={{ width: `${CONTAINER_WIDTH}px` }}>
      <Swiper
        data={data}
        itemWidth={300}
        containerWidth={CONTAINER_WIDTH}
        style={{ borderRadius: '12px' }}
      >
        {({ item, index }) => (
          <SwiperItem>
            <view
              style={{ width: '100%', height: '200px', backgroundColor: item }}
            >
              <text>Item {index}</text>
            </view>
          </SwiperItem>
        )}
      </Swiper>
    </view>
  )
}

Container Width

Styling

Render Props Mechanics

Recommended Prompt Formula

Scenario + Layout Mode/Align + Sizes (itemWidth, containerWidth) + Data + Interaction (loop, auto-play, bounces, RTL) + Callbacks + Optional custom animation

Examples:

3. Use Cases & Best Practices

Loop + Auto Play Example

<Swiper
  data={['red', 'green', 'yellow', 'purple']}
  itemWidth={315}
  itemHeight={220}
  containerWidth={320}
  loop
  autoPlay
  autoPlayInterval={2000}
  mode='normal'
  modeConfig={{ align: 'start', spaceBetween: 8 }}
  experimentalHorizontalSwipeOnly
>
  {({ item, index }) => (
    <SwiperItem>
      <view style={{ width: '100%', height: '100%', backgroundColor: item }} />
      <text>Number.{index}</text>
    </SwiperItem>
  )}
</Swiper>

Bounces Example

Note: startBounceItemWidth / endBounceItemWidth default to 50. This example sets endBounceItemWidth to 100 to demonstrate a larger overscroll resistance range.

<Swiper
  data={colors}
  itemWidth={250}
  itemHeight={200}
  containerWidth={320}
  mode='normal'
  bounceConfig={{
    enable: true,
    endBounceItemWidth: 100,
    endBounceItem: (
      <view style='display: linear; linear-orientation: vertical; height: 100%; width: 30px;'>
        <text>Show More</text>
      </view>
    ),
    onEndBounceItemBounce: ({ type, offset }) => {
      console.log('bounce', type, offset)
    },
  }}
>
  {({ index }) => (
    <SwiperItem>
      {/* content */}
    </SwiperItem>
  )}
</Swiper>

Custom Animation Example (`mode='custom'`)

import { interpolate, interpolateJS } from '@lynx-js/lynx-ui'

const ITEM_WIDTH = 250
const CONTAINER_WIDTH = 320

function customAnimation(value: number) {
  'main thread'
  const scale = interpolate(value, [-1, 0, 1], [0.8, 1, 0.8])
  const centerOffset = (CONTAINER_WIDTH - ITEM_WIDTH) / 2
  const translateX = interpolate(value, [-1, 0, 1], [
    -ITEM_WIDTH + centerOffset,
    centerOffset,
    ITEM_WIDTH + centerOffset,
  ], 'extend')
  return {
    transform: `translateX(${translateX}px) scale(${scale})`,
    'transform-origin': 'center',
  }
}

function customAnimationFirstScreen(value: number) {
  const scale = interpolateJS(value, [-1, 0, 1], [0.8, 1, 0.8])
  const centerOffset = (CONTAINER_WIDTH - ITEM_WIDTH) / 2
  const translateX = interpolateJS(value, [-1, 0, 1], [
    -ITEM_WIDTH + centerOffset,
    centerOffset,
    ITEM_WIDTH + centerOffset,
  ], 'extend')
  return {
    transform: `translateX(${translateX}px) scale(${scale})`,
    'transform-origin': 'center',
  }
}

<Swiper
  data={colors}
  itemWidth={ITEM_WIDTH}
  itemHeight={200}
  containerWidth={CONTAINER_WIDTH}
  mode='custom'
  main-thread:customAnimation={customAnimation}
  customAnimationFirstScreen={customAnimationFirstScreen}
>
  {({ index }) => (
    <SwiperItem>
      {/* content */}
    </SwiperItem>
  )}
</Swiper>

RTL Example

<Swiper
  data={items}
  itemWidth={300}
  itemHeight={200}
  containerWidth={320}
  mode='normal'
  modeConfig={{ align: 'start', spaceBetween: 8 }}
  RTL={true}
>
  {({ index }) => (
    <SwiperItem>
      {/* content */}
    </SwiperItem>
  )}
</Swiper>

4. Props Highlights

5. Ref API

interface SwiperRef {
  swipeNext(): void
  swipePrev(): void
  swipeTo(
    index: number,
    options?: { animate?: boolean, onFinished?: () => void },
  ): void
  cancelAnimation(): void // use with caution
}

6. FAQ

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.