-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: adjust inVirtual logic(#227) #262
Changes from all commits
f92dce2
a09308b
479a109
a6a00fe
bb65230
306dfcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,9 +113,28 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) { | |
...restProps | ||
} = props; | ||
|
||
// =============================== Item Key =============================== | ||
const getKey = React.useCallback<GetKey<T>>( | ||
(item: T) => { | ||
if (typeof itemKey === 'function') { | ||
return itemKey(item); | ||
} | ||
return item?.[itemKey as string]; | ||
}, | ||
[itemKey], | ||
); | ||
|
||
// ================================ Height ================================ | ||
const [setInstanceRef, collectHeight, heights, heightUpdatedMark] = useHeights( | ||
getKey, | ||
null, | ||
null, | ||
); | ||
|
||
// ================================= MISC ================================= | ||
const useVirtual = !!(virtual !== false && height && itemHeight); | ||
const inVirtual = useVirtual && data && (itemHeight * data.length > height || !!scrollWidth); | ||
const containerHeight = React.useMemo(() => Object.values(heights.maps).reduce((total, curr) => total + curr, 0), [heights.id, heights.maps]); | ||
const inVirtual = useVirtual && data && (Math.max(itemHeight * data.length, containerHeight) > height || !!scrollWidth); | ||
const isRTL = direction === 'rtl'; | ||
|
||
const mergedClassName = classNames(prefixCls, { [`${prefixCls}-rtl`]: isRTL }, className); | ||
|
@@ -136,17 +155,6 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) { | |
setScrollMoving(false); | ||
}; | ||
|
||
// =============================== Item Key =============================== | ||
const getKey = React.useCallback<GetKey<T>>( | ||
(item: T) => { | ||
if (typeof itemKey === 'function') { | ||
return itemKey(item); | ||
} | ||
return item?.[itemKey as string]; | ||
}, | ||
[itemKey], | ||
); | ||
|
||
const sharedConfig: SharedConfig<T> = { | ||
getKey, | ||
}; | ||
|
@@ -176,13 +184,6 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) { | |
const [diffItem] = useDiffItem(mergedData, getKey); | ||
diffItemRef.current = diffItem; | ||
|
||
// ================================ Height ================================ | ||
const [setInstanceRef, collectHeight, heights, heightUpdatedMark] = useHeights( | ||
getKey, | ||
null, | ||
null, | ||
); | ||
|
||
// ========================== Visible Calculation ========================= | ||
const { | ||
scrollHeight, | ||
|
@@ -307,6 +308,8 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) { | |
const getVirtualScrollInfo = () => ({ | ||
x: isRTL ? -offsetLeft : offsetLeft, | ||
y: offsetTop, | ||
maxScrollWidth: !!scrollWidth ? scrollWidth - size.width : 0, | ||
maxScrollHeight: scrollHeight > height ? maxScrollHeight : 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个的计算我怎么有点没看懂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maxScrollWidth:scrollWidth 可能不传,所以这里加了个判断。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这俩属性和bugfix无关,我发PR去掉先。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}); | ||
|
||
const lastVirtualScrollInfoRef = useRef(getVirtualScrollInfo()); | ||
|
@@ -354,7 +357,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) { | |
|
||
const keepInHorizontalRange = (nextOffsetLeft: number) => { | ||
let tmpOffsetLeft = nextOffsetLeft; | ||
const max = scrollWidth - size.width; | ||
const max = !!scrollWidth ? scrollWidth - size.width : 0; | ||
tmpOffsetLeft = Math.max(tmpOffsetLeft, 0); | ||
tmpOffsetLeft = Math.min(tmpOffsetLeft, max); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
尽量避免给测试用的打孔,这个去掉吧。测试换种方式测
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#264