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