Skip to content

Commit

Permalink
Fewer inbox tab renders (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis authored Jan 25, 2025
1 parent 2ee7f16 commit 355cba9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 13 additions & 1 deletion components/default-flat-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ const DefaultFlatList = forwardRef(<ItemT,>(props: DefaultFlatListProps<ItemT>,
useImperativeHandle(ref, () => ({ refresh: onRefresh }), [onRefresh]);

const onContentSizeChange = (width: number, height: number) => {
if (width === 0 && height === 0) {
// Measurement is inaccurate because the element is occluded
return;
}

contentHeight.current = height;

if (contentHeight.current < viewportHeight.current) {
Expand All @@ -343,7 +348,14 @@ const DefaultFlatList = forwardRef(<ItemT,>(props: DefaultFlatListProps<ItemT>,
};

const onLayout = useCallback((params) => {
viewportHeight.current = params.nativeEvent.layout.height;
const { height, width } = params.nativeEvent.layout;

if (width === 0 && height === 0) {
// Measurement is inaccurate because the element is occluded
return;
}

viewportHeight.current = height;

if (contentHeight.current < viewportHeight.current) {
fetchNextPage();
Expand Down
11 changes: 10 additions & 1 deletion components/inbox-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { signedInUser } from '../App';
import { Notice } from './notice';
import { listen, lastEvent } from '../events/events';
import { useScrollbar } from './navigation/scroll-bar-hooks';
import * as _ from "lodash";


const Stack = createNativeStackNavigator();
Expand Down Expand Up @@ -104,7 +105,15 @@ const InboxTab = ({navigation}) => {
useEffect(() => {
return listen<Inbox | null>(
'inbox',
(inbox) => setInbox(inbox ?? null),
(inbox) => {
setInbox((oldInbox) => {
if (_.isEqual(oldInbox, inbox)) {
return oldInbox ?? null
} else {
return inbox ?? null
}
});
},
true
);
}, []);
Expand Down

0 comments on commit 355cba9

Please sign in to comment.