Skip to content
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

migrate OptionsListSkeletonView to TS and fixes the theme switch issue #33567

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 0 additions & 114 deletions src/components/OptionsListSkeletonView.js

This file was deleted.

83 changes: 83 additions & 0 deletions src/components/OptionsListSkeletonView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, {useMemo, useState} from 'react';
import {View} from 'react-native';
import {Circle, Rect} from 'react-native-svg';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import SkeletonViewContentLoader from './SkeletonViewContentLoader';

type OptionsListSkeletonViewProps = {
shouldAnimate?: boolean;
};

function OptionsListSkeletonView({shouldAnimate = true}: OptionsListSkeletonViewProps) {
const theme = useTheme();
const themeStyles = useThemeStyles();

const [numItems, setNumItems] = useState(0);
const skeletonViewItems = useMemo(() => {
const items = [];
for (let i = 0; i < numItems; i++) {
const step = i % 3;
let lineWidth;
switch (step) {
case 0:
lineWidth = '100%';
break;
case 1:
lineWidth = '50%';
break;
default:
lineWidth = '25%';
}
items.push(
<SkeletonViewContentLoader
key={`skeletonViewItems${i}`}
animate={shouldAnimate}
height={CONST.LHN_SKELETON_VIEW_ITEM_HEIGHT}
backgroundColor={theme.skeletonLHNIn}
foregroundColor={theme.skeletonLHNOut}
style={themeStyles.mr5}
>
<Circle
cx="40"
cy="32"
r="20"
/>
<Rect
x="72"
y="18"
width="20%"
height="8"
/>
<Rect
x="72"
y="38"
width={lineWidth}
height="8"
/>
</SkeletonViewContentLoader>,
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
);
}
return items;
}, [numItems, shouldAnimate, theme, themeStyles]);

return (
<View
style={[themeStyles.flex1, themeStyles.overflowHidden]}
onLayout={(event) => {
const newNumItems = Math.ceil(event.nativeEvent.layout.height / CONST.LHN_SKELETON_VIEW_ITEM_HEIGHT);
if (newNumItems === numItems) {
return;
}
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
setNumItems(newNumItems);
}}
>
<View>{skeletonViewItems}</View>
</View>
);
}

OptionsListSkeletonView.displayName = 'OptionsListSkeletonView';

export default OptionsListSkeletonView;
Loading