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

chore: [IOBP-528] Added the loading status on ListItemNav component #187

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions example/src/pages/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ const renderListItemNav = () => (
}}
accessibilityLabel="Empty just for testing purposes"
/>
<ListItemNav
value={"Value"}
description="This is a list item nav with a loading indicator"
paymentLogo="bancomatPay"
onPress={() => {
alert("Action triggered");
}}
accessibilityLabel="Empty just for testing purposes"
loading
/>
<ListItemNav
value={"Value"}
description="This is a list item nav without chevron icon"
Expand Down
18 changes: 15 additions & 3 deletions src/components/listitems/ListItemNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { IOIcons, Icon } from "../icons";
import { IOLogoPaymentType, LogoPayment } from "../logos";
import { HSpacer, VSpacer } from "../spacer";
import { Caption, H6, LabelSmall } from "../typography";
import { LoadingSpinner } from "../loadingSpinner";

type ListItemTopElementProps =
| {
Expand All @@ -40,6 +41,7 @@ type ListItemTopElementProps =
type ListItemNavPartialProps = WithTestID<{
value: string | React.ReactNode;
description?: string | React.ReactNode;
loading?: boolean;
onPress: (event: GestureResponderEvent) => void;
// Accessibility
accessibilityLabel: string;
Expand All @@ -64,7 +66,8 @@ export const ListItemNav = ({
accessibilityLabel,
testID,
hideChevron = false,
topElement
topElement,
loading
}: ListItemNav) => {
const isPressed = useSharedValue(0);
const { isExperimental } = useIOExperimentalDesign();
Expand Down Expand Up @@ -167,9 +170,17 @@ export const ListItemNav = ({
isPressed.value = 0;
}, [isPressed]);

const handleOnPress = (event: GestureResponderEvent) => {
if (!loading) {
onPress(event);
}
};

const primaryColor: IOColors = isExperimental ? "blueIO-500" : "blue";

return (
<Pressable
onPress={onPress}
onPress={handleOnPress}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
accessible={true}
Expand Down Expand Up @@ -201,7 +212,8 @@ export const ListItemNav = ({
</View>
)}
<View style={IOStyles.flex}>{listItemNavContent}</View>
{!hideChevron && (
{loading && <LoadingSpinner color={primaryColor} />}
{!loading && !hideChevron && (
<View style={{ marginLeft: IOListItemVisualParams.iconMargin }}>
<Icon
name="chevronRightListItem"
Expand Down
Loading