Skip to content

Commit

Permalink
Merge pull request #92 from bamlab/add-ref-to-SpatialNavigationview
Browse files Browse the repository at this point in the history
feat: Add imperative focus to SpatialNavigationView
  • Loading branch information
pierpo committed Mar 28, 2024
2 parents 48b5841 + cad3e80 commit 174e5ee
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/lib/src/spatial-navigation/components/View.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import { StyleSheet, View, ViewStyle } from 'react-native';
import { SpatialNavigationNode } from './Node';
import { forwardRef } from 'react';
import { SpatialNavigationNodeRef } from '../types/SpatialNavigationNodeRef';

export const SpatialNavigationView = ({
direction = 'horizontal',
alignInGrid = false,
children,
style,
}: {
type Props = {
children: React.ReactNode;
style?: ViewStyle;
direction: 'horizontal' | 'vertical';
alignInGrid?: boolean;
}) => {
return (
<SpatialNavigationNode orientation={direction} alignInGrid={alignInGrid}>
<View
style={[style, direction === 'horizontal' ? styles.viewHorizontal : styles.viewVertical]}
>
{children}
</View>
</SpatialNavigationNode>
);
};

export const SpatialNavigationView = forwardRef<SpatialNavigationNodeRef, Props>(
({ direction = 'horizontal', alignInGrid = false, children, style }: Props, ref) => {
return (
<SpatialNavigationNode orientation={direction} alignInGrid={alignInGrid} ref={ref}>
<View
style={[style, direction === 'horizontal' ? styles.viewHorizontal : styles.viewVertical]}
>
{children}
</View>
</SpatialNavigationNode>
);
},
);
SpatialNavigationView.displayName = 'SpatialNavigationView';

const styles = StyleSheet.create({
viewVertical: {
display: 'flex',
Expand Down

0 comments on commit 174e5ee

Please sign in to comment.