Skip to content

feat: Reverse items stacking order #535

Merged
MatiPl01 merged 3 commits intomainfrom
feat/custom-items-order
Jan 13, 2026
Merged

feat: Reverse items stacking order #535
MatiPl01 merged 3 commits intomainfrom
feat/custom-items-order

Conversation

@MatiPl01
Copy link
Copy Markdown
Owner

Description

This PR adds a possibility to reverse items stacking order (render items with lower index below items with higher index).

Changes showcase

Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-01-13.at.19.36.46.mp4
Example source code
import { useCallback } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import type { SortableGridRenderItem } from 'react-native-sortables';
import Sortable from 'react-native-sortables';

import { ScrollScreen } from '@/components';
import { colors, radius, sizes, spacing, text } from '@/theme';

const DATA = Array.from({ length: 5 }, (_, index) => `Item ${index + 1}`);

export default function PlaygroundExample() {
  const renderItem = useCallback<SortableGridRenderItem<string>>(
    ({ item }) => (
      <View style={styles.card}>
        <Text style={styles.text}>{item}</Text>
        <View
          style={{
            backgroundColor: 'red',
            height: 40,
            position: 'absolute',
            right: -20,
            top: -20,
            width: 40
          }}
        />
      </View>
    ),
    []
  );

  return (
    <ScrollScreen contentContainerStyle={styles.container} includeNavBarHeight>
      <Sortable.Grid
        columnGap={10}
        columns={3}
        data={DATA}
        renderItem={renderItem}
        rowGap={10}
        stackingOrder='desc'
      />
    </ScrollScreen>
  );
}

const styles = StyleSheet.create({
  card: {
    alignItems: 'center',
    backgroundColor: '#36877F',
    borderRadius: radius.md,
    height: sizes.xl,
    justifyContent: 'center'
  },
  container: {
    padding: spacing.md
  },
  text: {
    ...text.label2,
    color: colors.white
  }
});

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
react-native-sortables-docs Ignored Ignored Preview Jan 13, 2026 6:47pm

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new stackingOrder prop to Sortable components that allows reversing the z-index stacking order of items. By default, items use ascending order (higher index = higher z-index), but with stackingOrder='desc', items with lower indices are rendered above items with higher indices.

Changes:

  • Added ItemsStackingOrder type with 'asc' and 'desc' values
  • Implemented z-index calculation logic in useItemZIndex hook to support descending order
  • Added stackingOrder prop to shared props with 'asc' as the default value

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/react-native-sortables/src/types/props/shared.ts Added ItemsStackingOrder type definition and stackingOrder prop to SharedProps
packages/react-native-sortables/src/types/providers/shared.ts Added isStackingOrderDesc boolean to context type
packages/react-native-sortables/src/providers/shared/hooks/useItemZIndex.ts Updated z-index calculation to support descending order
packages/react-native-sortables/src/providers/shared/CommonValuesProvider.ts Added stackingOrder prop and computed isStackingOrderDesc value
packages/react-native-sortables/src/providers/shared/SharedProvider.tsx Added stackingOrder to required props list
packages/react-native-sortables/src/constants/props.ts Added default value 'asc' for stackingOrder

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

MatiPl01 and others added 2 commits January 13, 2026 19:43
…ItemZIndex.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MatiPl01 MatiPl01 force-pushed the feat/custom-items-order branch from 9c213ad to a94bc07 Compare January 13, 2026 18:47
@MatiPl01 MatiPl01 merged commit 14c7d82 into main Jan 13, 2026
11 checks passed
@MatiPl01 MatiPl01 deleted the feat/custom-items-order branch January 13, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants