Skip to content

Commit

Permalink
Refactor to useWidthPerToken
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzaizzat committed Apr 23, 2024
1 parent d013eb1 commit 2b7b511
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 3 additions & 9 deletions apps/mobile/src/components/GalleryEditor/GalleryEditorRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import clsx from 'clsx';
import React, { useCallback } from 'react';
import { GestureResponderEvent, useWindowDimensions, View, ViewProps } from 'react-native';
import { GestureResponderEvent, View, ViewProps } from 'react-native';
import Animated from 'react-native-reanimated';
import { graphql, useFragment } from 'react-relay';

Expand All @@ -11,7 +11,7 @@ import { GalleryEditorRowFragment$key } from '~/generated/GalleryEditorRowFragme
import { GalleryTouchableOpacity } from '../GalleryTouchableOpacity';
import { GalleryEditorActiveActions } from './GalleryEditorActiveActions';
import { GalleryEditorTokenPreview } from './GalleryEditorTokenPreview';
import { horizontalRowPadding, inBetweenColumnPadding } from './utils';
import { useWidthPerToken } from './useWidthPerToken';

type Props = {
sectionId: string;
Expand All @@ -32,13 +32,7 @@ export function GalleryEditorRow({ sectionId, row, style, queryRef }: Props) {

const { activateRow, activeRowId } = useGalleryEditorActions();

const screenDimensions = useWindowDimensions();

const column = row.columns;
const totalSpaceForTokens =
screenDimensions.width - horizontalRowPadding * 2 - inBetweenColumnPadding * (column - 1);

const widthPerToken = totalSpaceForTokens / column;
const widthPerToken = useWidthPerToken(row.columns);

const handleSectionPress = useCallback(
(e: GestureResponderEvent) => {
Expand Down
11 changes: 11 additions & 0 deletions apps/mobile/src/components/GalleryEditor/useWidthPerToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useWindowDimensions } from 'react-native';
import { horizontalRowPadding, inBetweenColumnPadding } from './utils';

export function useWidthPerToken(columns: number) {
const screenDimensions = useWindowDimensions();

const totalSpaceForTokens =
screenDimensions.width - horizontalRowPadding * 2 - inBetweenColumnPadding * (columns - 1);

return totalSpaceForTokens / columns;
}

0 comments on commit 2b7b511

Please sign in to comment.