Skip to content

Commit

Permalink
fix container height
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzaizzat committed Apr 19, 2024
1 parent ce04073 commit 027dae4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 1 addition & 3 deletions apps/mobile/src/components/GalleryEditor/SortableRowList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useWindowDimensions, View } from 'react-native';
import { useSharedValue } from 'react-native-reanimated';
import { graphql, useFragment } from 'react-relay';

import { useGalleryEditorActions } from '~/contexts/GalleryEditor/GalleryEditorContext';
import { StagedRowList } from '~/contexts/GalleryEditor/types';
import { SortableRowListFragment$key } from '~/generated/SortableRowListFragment.graphql';

Expand Down Expand Up @@ -42,9 +41,8 @@ export function SortableRowList({ rows, sectionId, queryRef, onDragEnd }: Props)
queryRef
);
const screenDimensions = useWindowDimensions();
const { sections } = useGalleryEditorActions();

const rowOffsets = calculateOffsetsRow(sections, screenDimensions.width);
const rowOffsets = calculateOffsetsRow(rows, screenDimensions.width);

const initialPositions = calculatePositions(rows, screenDimensions.width);
const positions = useSharedValue<Positions>(initialPositions);
Expand Down
28 changes: 13 additions & 15 deletions apps/mobile/src/components/GalleryEditor/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StagedRow, StagedRowList, StagedSectionList } from '~/contexts/GalleryEditor/types';
import { StagedRow, StagedRowList } from '~/contexts/GalleryEditor/types';

import { ItemHeights, Positions } from './SortableRowList';

Expand All @@ -17,7 +17,7 @@ export function getRowHeight(row: StagedRow, screenDimensionsWidth: number) {

const heightPerToken = totalSpaceForTokens / column;

const linePerRow = Math.round(row.items.length / column);
const linePerRow = Math.ceil(row.items.length / column);

return heightPerToken * linePerRow;
}
Expand Down Expand Up @@ -48,25 +48,23 @@ export function calculateItemHeights(
return itemHeights;
}

export function calculateOffsetsRow(sections: StagedSectionList, screenDimensionsWidth: number) {
export function calculateOffsetsRow(rows: StagedRowList, screenDimensionsWidth: number) {
const rowOffsets: Offset[] = [];

sections.forEach((section) => {
let cumulativeHeight = 0;
let cumulativeHeight = 0;

section.rows.forEach((row) => {
const height = getRowHeight(row, screenDimensionsWidth);
rows.forEach((row) => {
const height = getRowHeight(row, screenDimensionsWidth);

const offset = {
...row,
y: cumulativeHeight,
height,
};
const offset = {
...row,
y: cumulativeHeight,
height,
};

cumulativeHeight += height;
cumulativeHeight += height;

rowOffsets.push(offset);
});
rowOffsets.push(offset);
});

return rowOffsets;
Expand Down

0 comments on commit 027dae4

Please sign in to comment.