Skip to content

Commit

Permalink
Remove bar separator from navigation scroll context
Browse files Browse the repository at this point in the history
  • Loading branch information
olmoh authored and MarkusPettersson98 committed Jan 13, 2025
1 parent d392b79 commit 9d1f8c5
Showing 1 changed file with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,55 @@ interface NavigationContainerProps {

interface NavigationContainerState {
showsBarTitle: boolean;
showsBarSeparator: boolean;
}

export const NavigationScrollContext = React.createContext<{
showsBarTitle: boolean;
onScroll: (event: IScrollEvent) => void;
}>({
showsBarTitle: false,
onScroll: () => {
throw new Error('NavigationScrollContext provider is missing.');
},
});

export class NavigationContainer extends React.Component<
NavigationContainerProps,
NavigationContainerState
> {
public state = {
state: NavigationContainerState = {
showsBarTitle: false,
showsBarSeparator: false,
};

public componentDidMount() {
componentDidMount() {
this.updateBarAppearance({ scrollLeft: 0, scrollTop: 0 });
}

public render() {
render() {
const { children } = this.props;
const { showsBarTitle } = this.state;

return (
<NavigationScrollContext.Provider
value={{
...this.state,
showsBarTitle,
onScroll: this.onScroll,
}}>
{this.props.children}
{children}
</NavigationScrollContext.Provider>
);
}

public onScroll = (event: IScrollEvent) => {
private onScroll = (event: IScrollEvent) => {
this.updateBarAppearance(event);
};

private updateBarAppearance(event: IScrollEvent) {
// that's where SettingsHeader.HeaderTitle intersects the navigation bar
const showsBarSeparator = event.scrollTop > 11;
private updateBarAppearance = ({ scrollTop }: IScrollEvent) => {
// Show the bar title when user scrolls past page title
const showsBarTitle = scrollTop > 20;

// that's when SettingsHeader.HeaderTitle goes behind the navigation bar
const showsBarTitle = event.scrollTop > 20;

if (
this.state.showsBarSeparator !== showsBarSeparator ||
this.state.showsBarTitle !== showsBarTitle
) {
this.setState({ showsBarSeparator, showsBarTitle });
if (this.state.showsBarTitle !== showsBarTitle) {
this.setState({ showsBarTitle });
}
}
};
}
export const NavigationScrollContext = React.createContext({
showsBarTitle: false,
showsBarSeparator: false,
onScroll(_event: IScrollEvent): void {
throw Error('NavigationScrollContext provider missing');
},
});

0 comments on commit 9d1f8c5

Please sign in to comment.