Skip to content

Commit 99b2008

Browse files
committed
feat: allow scroll
1 parent ed0368f commit 99b2008

File tree

7 files changed

+41
-20
lines changed

7 files changed

+41
-20
lines changed

.changeset/quick-pugs-perform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
"live-mobile": minor
3+
"@ledgerhq/native-ui": minor
34
---
45

56
feat: add trackings wallet v4 tour

apps/ledger-live-mobile/__tests__/jest-setup.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ jest.mock("~/analytics/segment", () => ({
143143
track: jest.fn(),
144144
setAnalyticsFeatureFlagMethod: jest.fn(),
145145
screen: jest.fn(),
146-
useTrack: jest.fn(() => jest.fn()),
147146
useAnalytics: jest.fn(() => ({
148147
track: jest.fn(),
149148
screen: jest.fn(),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const PAGE_TRACKING_WALLET_V4_TOUR = "Product Tour WV4";

apps/ledger-live-mobile/src/mvvm/features/WalletV4Tour/Drawer/hooks/useSlideFooterButtonViewModel.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCallback } from "react";
22
import { useSlidesContext } from "@ledgerhq/native-ui";
33
import { track } from "~/analytics";
4+
import { PAGE_TRACKING_WALLET_V4_TOUR } from "../const";
45

56
export const useSlideFooterButtonViewModel = (onClose: () => void) => {
67
const { totalSlides, currentIndex, goToNext, scrollProgressSharedValue } = useSlidesContext();
@@ -12,7 +13,7 @@ export const useSlideFooterButtonViewModel = (onClose: () => void) => {
1213
goToNext();
1314
track("button_clicked", {
1415
button: "Next",
15-
page: "Product Tour WV4",
16+
page: PAGE_TRACKING_WALLET_V4_TOUR,
1617
card: currentIndex + 1,
1718
});
1819
}, [currentIndex, goToNext]);
@@ -21,7 +22,7 @@ export const useSlideFooterButtonViewModel = (onClose: () => void) => {
2122
onClose();
2223
track("button_clicked", {
2324
button: "Discover my new portfolio",
24-
page: "Product Tour WV4",
25+
page: PAGE_TRACKING_WALLET_V4_TOUR,
2526
});
2627
}, [onClose]);
2728

apps/ledger-live-mobile/src/mvvm/features/WalletV4Tour/Drawer/hooks/useWalletV4TourDrawerViewModel.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { setHasSeenWalletV4Tour } from "~/actions/settings";
55
import { hasCompletedOnboardingSelector, hasSeenWalletV4TourSelector } from "~/reducers/settings";
66
import type { WalletV4TourDrawerViewModel } from "../types";
77
import { useTranslation } from "~/context/Locale";
8-
import { useTrack } from "~/analytics";
98
import animation01 from "../animations/01.lottie";
109
import animation02 from "../animations/02.lottie";
1110
import animation03 from "../animations/03.lottie";
11+
import { track } from "~/analytics";
12+
import { PAGE_TRACKING_WALLET_V4_TOUR } from "../const";
1213

1314
export const useWalletV4TourDrawerViewModel = (): WalletV4TourDrawerViewModel => {
1415
const dispatch = useDispatch();
15-
const track = useTrack();
1616
const currentIndexRef = useRef(0);
1717
const hasSeenTour = useSelector(hasSeenWalletV4TourSelector);
1818
const hasCompletedOnboarding = useSelector(hasCompletedOnboardingSelector);
@@ -39,22 +39,19 @@ export const useWalletV4TourDrawerViewModel = (): WalletV4TourDrawerViewModel =>
3939
const closeDrawer = useCallback(() => {
4040
track("button_clicked", {
4141
button: "Close",
42-
page: "Product Tour WV4",
42+
page: PAGE_TRACKING_WALLET_V4_TOUR,
4343
card: currentIndexRef.current + 1,
4444
});
4545
handleCloseDrawer();
46-
}, [handleCloseDrawer, track]);
46+
}, [handleCloseDrawer]);
4747

48-
const onSlideChange = useCallback(
49-
(index: number) => {
50-
currentIndexRef.current = index;
51-
track("product_tour_card", {
52-
page: "Product Tour WV4",
53-
card: index + 1,
54-
});
55-
},
56-
[track],
57-
);
48+
const onSlideChange = useCallback((index: number) => {
49+
currentIndexRef.current = index;
50+
track("product_tour_card", {
51+
page: PAGE_TRACKING_WALLET_V4_TOUR,
52+
card: index + 1,
53+
});
54+
}, []);
5855

5956
const { t } = useTranslation();
6057
const slides = useMemo(

apps/ledger-live-mobile/src/mvvm/features/WalletV4Tour/Drawer/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { SlideFooterButton } from "./components/SlideFooterButton";
1010
import { StyleSheet } from "react-native";
1111
import { ProgressIndicator } from "./components/ProgressIndicator";
1212
import { TrackScreen } from "~/analytics";
13+
import { PAGE_TRACKING_WALLET_V4_TOUR } from "./const";
1314

1415
export const useWalletV4TourDrawer = () => {
1516
return useWalletV4TourDrawerViewModel();
@@ -43,13 +44,13 @@ export const WalletV4TourDrawer = ({
4344
noCloseButton={false}
4445
animateOnMount={false}
4546
>
46-
<TrackScreen page="Product Tour WV4" source="Portfolio" />
47+
<TrackScreen page={PAGE_TRACKING_WALLET_V4_TOUR} source="Wallet" />
4748
<Slides
48-
scrollEnabled={false}
4949
bounces={false}
5050
as={AnimatedGestureHandlerFlatList}
5151
testID="walletv4-tour-slides-container"
5252
initialNumToRender={1}
53+
maxToRenderPerBatch={1}
5354
onSlideChange={onSlideChange}
5455
>
5556
<Slides.Content>

libs/ui/packages/native/src/components/Layout/Slides/Slides.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,27 @@ export function Slides({
157157
[currentIndex, totalSlides, goToNext, goToPrevious, goToSlide],
158158
);
159159

160+
const onViewableItemsChanged = useCallback(
161+
({
162+
viewableItems,
163+
}: {
164+
viewableItems: Array<{
165+
index: number;
166+
key: string;
167+
isViewable: boolean;
168+
}>;
169+
}) => {
170+
const items = viewableItems.filter((item) => item.isViewable);
171+
172+
// Since it's a horizontal scroll view, and we display one by one, we only want to trigger the onSlideChange event when one item is visible.
173+
if (items.length === 1) {
174+
const index = items[0].index;
175+
onSlideChange?.(index);
176+
}
177+
},
178+
[onSlideChange],
179+
);
180+
160181
const renderOrderedChildren = useCallback(() => {
161182
return React.Children.map(children, (child) => {
162183
if (isElementOfType(child, Content)) {
@@ -177,7 +198,7 @@ export function Slides({
177198
scrollEventThrottle={16}
178199
getItemLayout={getItemLayout}
179200
initialScrollIndex={initialSlideIndex}
180-
onViewableItemsChanged={onSlideChange}
201+
onViewableItemsChanged={onViewableItemsChanged}
181202
{...flatListProps}
182203
/>
183204
);

0 commit comments

Comments
 (0)