@ledgerhq/native-ui 0.11.0-nightly.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { Props as FlexProps } from "../../Flex";
3
+ import { ItemStatus } from ".";
3
4
  export declare type Props = FlexProps & {
4
- status: "inactive" | "active" | "completed";
5
+ status: ItemStatus;
5
6
  isFirstItem?: boolean;
6
7
  isLastItem?: boolean;
7
8
  };
@@ -5,5 +5,7 @@ export declare type Props = {
5
5
  formatEstimatedTime?: (_: number) => string;
6
6
  isFirstItem?: boolean;
7
7
  isLastItem?: boolean;
8
+ setActiveIndex?: (_: number) => void;
9
+ index: number;
8
10
  };
9
- export default function TimelineItem({ item, formatEstimatedTime, isFirstItem, isLastItem, }: Props): JSX.Element;
11
+ export default function TimelineItem({ item, formatEstimatedTime, isFirstItem, isLastItem, setActiveIndex, index, }: Props): JSX.Element;
@@ -1,5 +1,6 @@
1
- import React, { useCallback, useState } from "react";
2
- import Animated, { Easing, useAnimatedStyle, useDerivedValue, withTiming, } from "react-native-reanimated";
1
+ import React, { useCallback } from "react";
2
+ import { Pressable } from "react-native";
3
+ import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
3
4
  import styled from "styled-components/native";
4
5
  import { Flex } from "../..";
5
6
  import { Text, Tag } from "../../..";
@@ -38,36 +39,45 @@ const Container = styled(Flex) `
38
39
  border: 1px solid ${(p) => getContainerBorder(p.theme, p.status, p.isLastItem)};
39
40
  padding: 20px 16px;
40
41
  `;
41
- export default function TimelineItem({ item, formatEstimatedTime, isFirstItem, isLastItem, }) {
42
- const [height, setHeight] = useState(0);
43
- const transition = useDerivedValue(() => {
44
- return item.status === "active"
45
- ? withTiming(1, { duration: 300, easing: Easing.out(Easing.linear) })
46
- : withTiming(0, { duration: 300, easing: Easing.in(Easing.linear) });
47
- }, [item.status]);
48
- const handleLayoutChange = useCallback((event) => {
49
- var _a, _b;
50
- if (height === 0 && ((_b = (_a = event === null || event === void 0 ? void 0 : event.nativeEvent) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.height) > 0) {
51
- setHeight(event.nativeEvent.layout.height);
52
- }
53
- }, [setHeight, height]);
54
- const style = useAnimatedStyle(() => ({
55
- height: transition.value * height + 1,
56
- overflow: "hidden",
57
- }), [height, transition.value]);
58
- return (React.createElement(Flex, { flexDirection: "row" },
59
- React.createElement(TimelineIndicator, { status: item.status, isFirstItem: isFirstItem, isLastItem: isLastItem, mr: 4 }),
60
- React.createElement(Container, { status: item.status, isLastItem: isLastItem, mb: 4 },
61
- React.createElement(Flex, { flexDirection: "row", justifyContent: "space-between" },
62
- React.createElement(Text, { variant: "body", color: item.status === "inactive"
63
- ? "neutral.c80"
64
- : isLastItem
65
- ? "success.c100"
66
- : "primary.c90" }, item.title),
67
- (item === null || item === void 0 ? void 0 : item.estimatedTime) && item.status === "active" && (React.createElement(Tag, null, formatEstimatedTime
68
- ? formatEstimatedTime(item.estimatedTime)
69
- : `${item.estimatedTime / 60} min`))),
70
- React.createElement(Animated.View, { style: style }, item.renderBody && (React.createElement(Flex, { position: "relative" },
71
- React.createElement(Flex, { onLayout: handleLayoutChange, pt: 6, position: "absolute", opacity: 0 }, item.renderBody(false)),
72
- React.createElement(Flex, { pt: 6 }, item.renderBody(item.status === "active"))))))));
42
+ export default function TimelineItem({ item, formatEstimatedTime, isFirstItem, isLastItem, setActiveIndex, index, }) {
43
+ /**
44
+ * Having an initial value of null will prevent having "height: 0" before the
45
+ * initial call of onLayout.
46
+ * The component will just layout normally without an animation which is ok
47
+ * since this will happen only on the first step.
48
+ * Without this default behavior, there are issues on iOS where sometimes the
49
+ * height is stuck at 0.
50
+ */
51
+ const sharedHeight = useSharedValue(null);
52
+ const handleLayout = useCallback(({ nativeEvent: { layout } }) => {
53
+ sharedHeight.value = withTiming(layout.height, { duration: 300 });
54
+ }, [sharedHeight]);
55
+ const animatedStyle = useAnimatedStyle(() => {
56
+ var _a;
57
+ return ({
58
+ /**
59
+ * If it's null the component still renders normally at its full height
60
+ * without its height being derived from an animated value.
61
+ */
62
+ height: (_a = sharedHeight.value) !== null && _a !== void 0 ? _a : undefined,
63
+ });
64
+ }, []);
65
+ const handlePress = useCallback(() => {
66
+ setActiveIndex && setActiveIndex(index);
67
+ }, [setActiveIndex, index]);
68
+ return (React.createElement(Pressable, { onPress: handlePress },
69
+ React.createElement(Flex, { flexDirection: "row" },
70
+ React.createElement(TimelineIndicator, { status: item.status, isFirstItem: isFirstItem, isLastItem: isLastItem, mr: 4 }),
71
+ React.createElement(Container, { status: item.status, isLastItem: isLastItem, mb: 4 },
72
+ React.createElement(Flex, { flexDirection: "row", justifyContent: "space-between" },
73
+ React.createElement(Text, { variant: "body", color: item.status === "inactive"
74
+ ? "neutral.c80"
75
+ : isLastItem
76
+ ? "success.c100"
77
+ : "primary.c90" }, item.title),
78
+ (item === null || item === void 0 ? void 0 : item.estimatedTime) && item.status === "active" && (React.createElement(Tag, null, formatEstimatedTime
79
+ ? formatEstimatedTime(item.estimatedTime)
80
+ : `${item.estimatedTime / 60} min`))),
81
+ React.createElement(Animated.ScrollView, { style: animatedStyle },
82
+ React.createElement(Animated.View, { onLayout: handleLayout }, item.renderBody && item.status === "active" ? (React.createElement(Flex, { pt: 6 }, item.renderBody(true))) : null))))));
73
83
  }
@@ -1,6 +1,10 @@
1
1
  import { ReactNode } from "react";
2
2
  import { BaseStyledProps } from "src/components/styled";
3
- export declare type ItemStatus = "inactive" | "active" | "completed";
3
+ export declare enum ItemStatus {
4
+ inactive = "inactive",
5
+ active = "active",
6
+ completed = "completed"
7
+ }
4
8
  export declare type Item = {
5
9
  status: ItemStatus;
6
10
  title: string;
@@ -10,5 +14,10 @@ export declare type Item = {
10
14
  export declare type Props = BaseStyledProps & {
11
15
  steps?: Item[];
12
16
  formatEstimatedTime?: (_: number) => string;
17
+ setActiveIndex?: (arg0: number) => void;
13
18
  };
14
- export default function VerticalTimeline({ steps, formatEstimatedTime, ...props }: Props): JSX.Element;
19
+ declare function VerticalTimeline({ steps, formatEstimatedTime, setActiveIndex, ...props }: Props): JSX.Element;
20
+ declare namespace VerticalTimeline {
21
+ var ItemStatus: typeof import(".").ItemStatus;
22
+ }
23
+ export default VerticalTimeline;
@@ -12,7 +12,14 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import React from "react";
13
13
  import TimelineItem from "./TimelineItem";
14
14
  import { Flex } from "../..";
15
+ export var ItemStatus;
16
+ (function (ItemStatus) {
17
+ ItemStatus["inactive"] = "inactive";
18
+ ItemStatus["active"] = "active";
19
+ ItemStatus["completed"] = "completed";
20
+ })(ItemStatus || (ItemStatus = {}));
15
21
  export default function VerticalTimeline(_a) {
16
- var { steps, formatEstimatedTime } = _a, props = __rest(_a, ["steps", "formatEstimatedTime"]);
17
- return (React.createElement(Flex, Object.assign({}, props, { flexDirection: "column" }), steps === null || steps === void 0 ? void 0 : steps.map((step, index) => (React.createElement(TimelineItem, { key: step.title, item: step, formatEstimatedTime: formatEstimatedTime, isFirstItem: index === 0, isLastItem: index === steps.length - 1 })))));
22
+ var { steps, formatEstimatedTime, setActiveIndex } = _a, props = __rest(_a, ["steps", "formatEstimatedTime", "setActiveIndex"]);
23
+ return (React.createElement(Flex, Object.assign({}, props, { flexDirection: "column" }), steps === null || steps === void 0 ? void 0 : steps.map((step, index) => (React.createElement(TimelineItem, { key: step.title, item: step, formatEstimatedTime: formatEstimatedTime, isFirstItem: index === 0, isLastItem: index === steps.length - 1, setActiveIndex: setActiveIndex, index: index })))));
18
24
  }
25
+ VerticalTimeline.ItemStatus = ItemStatus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/native-ui",
3
- "version": "0.11.0-nightly.0",
3
+ "version": "0.11.0",
4
4
  "description": "Ledger Live - Mobile UI",
5
5
  "repository": {
6
6
  "type": "git",