Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 12bd4fd

Browse files
authored
[WINDOW]: drop rtl support. (#161)
1 parent 618d8ad commit 12bd4fd

File tree

10 files changed

+22
-95
lines changed

10 files changed

+22
-95
lines changed

.changeset/khaki-onions-drum.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@resembli/react-virtualized-window": minor
3+
---
4+
5+
Removed rtl support
6+
7+
RTL support with `sticky` positioning is not widely supported, in particular it breaks in IOS touch devices.
8+
The decision was made to drop RTL support in the virtualized window due to the complexity supporting brings vs
9+
the actual use cases. If we need to support virtualized rtl views, this can be done through a separate purpose
10+
built package.

packages/react-virtualized-window/src/PinnedColumn.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface PinnedColumnsProps<T> {
99
position?: "sticky" | "absolute"
1010
left?: number
1111
right?: number
12-
rtl?: boolean
1312
columns: T[][]
1413
widths: number[]
1514
heights: number[]
@@ -30,7 +29,6 @@ export function PinnedColumn<T>({
3029
columns,
3130
widths,
3231
heights,
33-
rtl,
3432
runningHeight,
3533
Component,
3634
vertStart,
@@ -53,10 +51,8 @@ export function PinnedColumn<T>({
5351
{columns.map((pinnedColumn, colIndex) => {
5452
const columnWidth = widths[colIndex]
5553

56-
const marginLeft =
57-
pinnedRight && !rtl ? horizontalGap : !rtl && colIndex !== 0 ? horizontalGap : 0
58-
const marginRight =
59-
pinnedRight && rtl ? horizontalGap : rtl && colIndex !== 0 ? horizontalGap : 0
54+
const marginLeft = !pinnedRight && colIndex !== 0 ? horizontalGap : 0
55+
const marginRight = pinnedRight && colIndex !== columns.length - 1 ? horizontalGap : 0
6056

6157
return (
6258
<div key={colIndex}>

packages/react-virtualized-window/src/ScrollDiv.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from "react"
22
import type { PropsWithChildren } from "react"
33

44
interface ScrollDivProps {
5-
rtl?: boolean
65
disableSticky?: boolean
76
leftOffset: number
87
topOffset: number
@@ -11,31 +10,12 @@ interface ScrollDivProps {
1110
}
1211

1312
export function ScrollDiv({
14-
rtl,
1513
disableSticky,
1614
leftOffset,
1715
topOffset,
1816
pinnedLeftWidth,
1917
children,
2018
}: PropsWithChildren<ScrollDivProps>) {
21-
if (rtl) {
22-
return (
23-
<div
24-
style={{
25-
position: "absolute",
26-
transform: `translate3d(${disableSticky ? 0 : leftOffset}px, ${
27-
disableSticky ? 0 : -topOffset
28-
}px, 0px)`,
29-
top: 0,
30-
right: pinnedLeftWidth,
31-
willChange: "transform",
32-
}}
33-
>
34-
{children}
35-
</div>
36-
)
37-
}
38-
3919
return (
4020
<div
4121
style={{

packages/react-virtualized-window/src/StickyDiv.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ import * as React from "react"
33
interface StickyDivProps {
44
width?: React.CSSProperties["width"]
55
height?: React.CSSProperties["height"]
6-
rtl: boolean
76
disabled: boolean
87
}
98

109
export function StickyDiv({
1110
children,
1211
width,
1312
height,
14-
rtl,
1513
disabled,
1614
}: React.PropsWithChildren<StickyDivProps>) {
1715
if (disabled) return <>{children}</>
@@ -20,8 +18,7 @@ export function StickyDiv({
2018
style={{
2119
position: "sticky",
2220
top: 0,
23-
left: rtl ? undefined : 0,
24-
right: rtl ? 0 : undefined,
21+
left: 0,
2522
willChange: "top, left",
2623
height,
2724
width,

packages/react-virtualized-window/src/components/Grid.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { getHorizontalGap, getVerticalGap } from "../itemGapUtilities"
88
import type { GridProps } from "../types"
99
import { useDataDimension } from "../useDataDimension"
1010
import { useIndicesForDimensions } from "../useDimensionIndices"
11-
import { useRTLWarnings } from "../useRtlWarnings"
1211
import { useScrollAdjustWindowDims } from "../useScrollAdjustedDim"
1312
import { useScrollItems } from "../useScrollItems"
1413
import { useSmartSticky } from "../useSmartSticky"
@@ -35,8 +34,6 @@ export function Grid<T, L = unknown, R = unknown>({
3534
style,
3635
gap,
3736

38-
rtl,
39-
4037
width: sizingWidth,
4138
height: sizingHeight,
4239

@@ -56,11 +53,8 @@ export function Grid<T, L = unknown, R = unknown>({
5653
const [width, height, browserWidth] = useWindowDimensions(windowRef)
5754
const [overscan, disableSticky] = useSmartSticky(browserWidth, userOverscan, userDisableSticky)
5855

59-
useRTLWarnings({ rtl, disableSticky, pinnedLeft, pinnedRight })
60-
6156
const [topOffset, leftOffset, onScroll] = useWindowScroll({
6257
userOnScroll,
63-
rtl: rtl ?? false,
6458
})
6559

6660
const [adjustedWidth, adjustedHeight] = useScrollAdjustWindowDims({
@@ -133,7 +127,6 @@ export function Grid<T, L = unknown, R = unknown>({
133127
horiEnd,
134128
horiStart,
135129
horizontalGap,
136-
rtl,
137130
runningHeight,
138131
runningWidth,
139132
vertEnd,
@@ -159,7 +152,6 @@ export function Grid<T, L = unknown, R = unknown>({
159152
width,
160153
position: "relative",
161154
overflow: "auto",
162-
direction: rtl ? "rtl" : "ltr",
163155
}}
164156
>
165157
<div
@@ -170,12 +162,10 @@ export function Grid<T, L = unknown, R = unknown>({
170162
>
171163
<StickyDiv
172164
disabled={disableSticky ?? false}
173-
rtl={rtl ?? false}
174165
height={adjustedHeight}
175166
width={adjustedWidth}
176167
>
177168
<ScrollDiv
178-
rtl={rtl}
179169
disableSticky={disableSticky}
180170
topOffset={topOffset}
181171
leftOffset={leftOffset}
@@ -187,18 +177,16 @@ export function Grid<T, L = unknown, R = unknown>({
187177
<div
188178
style={{
189179
display: "flex",
190-
width: adjustedWidth,
180+
width: width,
191181
position: "sticky",
192-
left: rtl ? undefined : 0,
193-
right: rtl ? 0 : undefined,
182+
left: 0,
194183
}}
195184
>
196185
{pinnedLeft && (
197186
<PinnedColumn
198187
Component={children}
199188
totalWidth={leftTotalWidth}
200-
left={rtl ? undefined : 0}
201-
right={rtl ? 0 : undefined}
189+
left={0}
202190
topOffset={disableSticky ? 0 : -topOffset}
203191
columns={pinnedLeft}
204192
widths={lWidths}
@@ -208,15 +196,13 @@ export function Grid<T, L = unknown, R = unknown>({
208196
verticalGap={verticalGap}
209197
horizontalGap={horizontalGap}
210198
runningHeight={runningHeight}
211-
rtl={rtl}
212199
/>
213200
)}
214201
{pinnedRight && (
215202
<PinnedColumn
216203
Component={children}
217204
totalWidth={rightTotalWidth}
218-
left={rtl ? 0 : undefined}
219-
right={rtl ? undefined : 0}
205+
right={0}
220206
topOffset={disableSticky ? 0 : -topOffset}
221207
columns={pinnedRight}
222208
widths={rWidths}
@@ -227,7 +213,6 @@ export function Grid<T, L = unknown, R = unknown>({
227213
horizontalGap={horizontalGap}
228214
pinnedRight
229215
runningHeight={runningHeight}
230-
rtl={rtl}
231216
/>
232217
)}
233218
</div>

packages/react-virtualized-window/src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export interface VirtualWindowBaseProps<T> {
1515
gap?: ItemGap
1616
disableSticky?: boolean
1717

18-
rtl?: boolean
19-
2018
onScroll?: React.UIEventHandler<HTMLElement>
2119

2220
width?: React.CSSProperties["width"]

packages/react-virtualized-window/src/useRtlWarnings.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/react-virtualized-window/src/useScrollItems.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ interface ScrollItemArgs<T> {
1717
horizontalGap: number
1818
getKey: GridProps<T>["getKey"]
1919
children: GridProps<T>["children"]
20-
rtl?: boolean
2120
}
2221

2322
export function useScrollItems<T>({
@@ -29,7 +28,6 @@ export function useScrollItems<T>({
2928
horiEnd,
3029
horiStart,
3130
horizontalGap,
32-
rtl,
3331
runningHeight,
3432
runningWidth,
3533
vertEnd,
@@ -54,8 +52,8 @@ export function useScrollItems<T>({
5452
key={cellKey}
5553
itemWidth={itemWidth}
5654
Component={children}
57-
marginLeft={rtl || j + horiStart === 0 ? 0 : horizontalGap}
58-
marginRight={!rtl || j + horiStart === 0 ? 0 : horizontalGap}
55+
marginLeft={j + horiStart === 0 ? 0 : horizontalGap}
56+
marginRight={0}
5957
itemProps={cell}
6058
column={horiStart + j}
6159
row={vertStart + i}
@@ -92,7 +90,6 @@ export function useScrollItems<T>({
9290
horiEnd,
9391
horiStart,
9492
horizontalGap,
95-
rtl,
9693
runningHeight,
9794
runningWidth,
9895
vertEnd,

packages/react-virtualized-window/src/useWindowScroll.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as React from "react"
22

33
interface UseWindowScrollArgs {
4-
rtl: boolean
54
userOnScroll?: React.UIEventHandler<HTMLElement>
65
}
76

8-
export const useWindowScroll = ({ userOnScroll, rtl }: UseWindowScrollArgs) => {
7+
export const useWindowScroll = ({ userOnScroll }: UseWindowScrollArgs) => {
98
const vOffset = React.useRef(0)
109
const hOffset = React.useRef(0)
1110

@@ -16,7 +15,7 @@ export const useWindowScroll = ({ userOnScroll, rtl }: UseWindowScrollArgs) => {
1615
(event) => {
1716
const target = event.currentTarget
1817

19-
const scrollLeft = rtl ? -target.scrollLeft : target.scrollLeft
18+
const scrollLeft = target.scrollLeft
2019
const scrollTop = target.scrollTop
2120

2221
const verticalOffset = Math.max(0, scrollTop)
@@ -31,7 +30,7 @@ export const useWindowScroll = ({ userOnScroll, rtl }: UseWindowScrollArgs) => {
3130

3231
userOnScroll?.(event)
3332
},
34-
[rtl, userOnScroll],
33+
[userOnScroll],
3534
)
3635

3736
return [vOffset.current, hOffset.current, onScroll] as const

playgrounds/src/App.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,11 @@ const pinnedRight = [
5050
]
5151

5252
function App() {
53-
const [rtl, setRlt] = useState(false)
5453
const [disableSticky, setStickyDisabled] = useState(false)
5554

5655
return (
5756
<div className={AppCss()}>
5857
<div>
59-
<label>
60-
rtl:
61-
<input type="checkbox" checked={rtl} onChange={(e) => setRlt(e.target.checked)} />
62-
</label>
6358
<label>
6459
disableStick:
6560
<input
@@ -75,7 +70,6 @@ function App() {
7570
data={data}
7671
width="70%"
7772
height="70%"
78-
rtl={rtl}
7973
disableSticky={disableSticky}
8074
pinnedRight={pinnedRight}
8175
pinnedLeft={pinnedLeft}

0 commit comments

Comments
 (0)