|
|
@ -4,7 +4,7 @@ import omit from 'rc-util/lib/omit'; |
|
|
|
import * as React from 'react'; |
|
|
|
import type { ConfigConsumerProps } from '../config-provider'; |
|
|
|
import { ConfigContext } from '../config-provider'; |
|
|
|
import { throttleByAnimationFrameDecorator } from '../_util/throttleByAnimationFrame'; |
|
|
|
import throttleByAnimationFrame from '../_util/throttleByAnimationFrame'; |
|
|
|
|
|
|
|
import useStyle from './style'; |
|
|
|
import { |
|
|
@ -126,9 +126,9 @@ class Affix extends React.Component<InternalAffixProps, AffixState> { |
|
|
|
componentWillUnmount() { |
|
|
|
clearTimeout(this.timeout); |
|
|
|
removeObserveTarget(this); |
|
|
|
(this.updatePosition as any).cancel(); |
|
|
|
this.updatePosition.cancel(); |
|
|
|
// https://github.com/ant-design/ant-design/issues/22683
|
|
|
|
(this.lazyUpdatePosition as any).cancel(); |
|
|
|
this.lazyUpdatePosition.cancel(); |
|
|
|
} |
|
|
|
|
|
|
|
getOffsetTop = () => { |
|
|
@ -228,14 +228,11 @@ class Affix extends React.Component<InternalAffixProps, AffixState> { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// Handle realign logic
|
|
|
|
@throttleByAnimationFrameDecorator() |
|
|
|
updatePosition() { |
|
|
|
updatePosition = throttleByAnimationFrame(() => { |
|
|
|
this.prepareMeasure(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
@throttleByAnimationFrameDecorator() |
|
|
|
lazyUpdatePosition() { |
|
|
|
lazyUpdatePosition = throttleByAnimationFrame(() => { |
|
|
|
const targetFunc = this.getTargetFunc(); |
|
|
|
const { affixStyle } = this.state; |
|
|
|
|
|
|
@ -262,7 +259,7 @@ class Affix extends React.Component<InternalAffixProps, AffixState> { |
|
|
|
|
|
|
|
// Directly call prepare measure since it's already throttled.
|
|
|
|
this.prepareMeasure(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// =================== Render ===================
|
|
|
|
render() { |
|
|
@ -288,21 +285,11 @@ class Affix extends React.Component<InternalAffixProps, AffixState> { |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
|
<ResizeObserver |
|
|
|
onResize={() => { |
|
|
|
this.updatePosition(); |
|
|
|
}} |
|
|
|
> |
|
|
|
<ResizeObserver onResize={this.updatePosition}> |
|
|
|
<div {...props} ref={this.savePlaceholderNode}> |
|
|
|
{affixStyle && <div style={placeholderStyle} aria-hidden="true" />} |
|
|
|
<div className={className} ref={this.saveFixedNode} style={affixStyle}> |
|
|
|
<ResizeObserver |
|
|
|
onResize={() => { |
|
|
|
this.updatePosition(); |
|
|
|
}} |
|
|
|
> |
|
|
|
{children} |
|
|
|
</ResizeObserver> |
|
|
|
<ResizeObserver onResize={this.updatePosition}>{children}</ResizeObserver> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</ResizeObserver> |
|
|
@ -321,7 +308,6 @@ const AffixFC = React.forwardRef<Affix, AffixProps>((props, ref) => { |
|
|
|
|
|
|
|
const AffixProps: InternalAffixProps = { |
|
|
|
...props, |
|
|
|
|
|
|
|
affixPrefixCls, |
|
|
|
rootClassName: hashId, |
|
|
|
}; |
|
|
|