Skip to content

Commit 28c9099

Browse files
authored
feat: Add style property to the handle component (#477)
## Description This PR just adds a `style` property to the `Sortable.Handle` component as it might be sometimes useful while styling the helper `View` component.
1 parent 11cf84a commit 28c9099

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

packages/react-native-sortables/bob.config.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module.exports = {
22
source: 'src',
33
output: 'dist',
4-
exclude: '{**/{__tests__,__fixtures__,__mocks__}/**,**/*.test.{js,jsx,ts,tsx}}',
4+
exclude:
5+
'{**/{__tests__,__fixtures__,__mocks__}/**,**/*.test.{js,jsx,ts,tsx}}',
56
targets: [
67
['module', { configFile: true }],
78
['typescript', { project: 'tsconfig.build.json' }]

packages/react-native-sortables/src/components/shared/CustomHandle.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type PropsWithChildren, useCallback, useEffect } from 'react';
2+
import type { StyleProp, ViewStyle } from 'react-native';
23
import { View } from 'react-native';
34
import { GestureDetector } from 'react-native-gesture-handler';
45
import { runOnUI, useAnimatedRef } from 'react-native-reanimated';
@@ -12,6 +13,7 @@ import { error } from '../../utils';
1213

1314
/** Props for the Sortable Handle component */
1415
export type CustomHandleProps = PropsWithChildren<{
16+
style?: StyleProp<ViewStyle>;
1517
/** Controls how the item behaves in the sortable component
1618
* - 'draggable': Item can be dragged and moves with reordering (default)
1719
* - 'non-draggable': Item cannot be dragged but moves with reordering
@@ -21,23 +23,30 @@ export type CustomHandleProps = PropsWithChildren<{
2123
mode?: 'draggable' | 'fixed-order' | 'non-draggable';
2224
}>;
2325

24-
export default function CustomHandle(props: CustomHandleProps) {
26+
export default function CustomHandle({
27+
children,
28+
mode,
29+
style
30+
}: CustomHandleProps) {
2531
// The item is teleported when it is rendered within the PortalOutlet
2632
// component
2733
const isTeleported = useIsInPortalOutlet();
2834

2935
// In case of teleported handle items, we want to render just the
3036
// handle component without any functionality
3137
return isTeleported ? (
32-
<View>{props.children}</View>
38+
<View style={style}>{children}</View>
3339
) : (
34-
<CustomHandleComponent {...props} />
40+
<CustomHandleComponent mode={mode} style={style}>
41+
{children}
42+
</CustomHandleComponent>
3543
);
3644
}
3745

3846
function CustomHandleComponent({
3947
children,
40-
mode = 'draggable'
48+
mode = 'draggable',
49+
style
4150
}: CustomHandleProps) {
4251
const customHandleContext = useCustomHandleContext();
4352
if (!customHandleContext) {
@@ -66,7 +75,11 @@ function CustomHandleComponent({
6675

6776
return (
6877
<GestureDetector gesture={gesture.enabled(dragEnabled)} userSelect='none'>
69-
<View collapsable={false} ref={handleRef} onLayout={runOnUI(onLayout)}>
78+
<View
79+
collapsable={false}
80+
ref={handleRef}
81+
style={style}
82+
onLayout={runOnUI(onLayout)}>
7083
{children}
7184
</View>
7285
</GestureDetector>

0 commit comments

Comments
 (0)