@ledgerhq/native-ui 0.11.0-nightly.0 → 0.12.0-next.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.
@@ -2,9 +2,15 @@ import React, { useEffect, useState, useRef, useCallback } from "react";
2
2
  import { Platform } from "react-native";
3
3
  import styled from "styled-components/native";
4
4
  import { Flex, SlideIndicator } from "../index";
5
+ import { I18nManager } from "react-native";
5
6
  const HorizontalScrollView = styled.ScrollView.attrs({ horizontal: true }) `
6
7
  flex: 1;
7
8
  `;
9
+ /*
10
+ In RTL activated, this carousel is making a jump to the last item at start. It's patched by scrolling back to the activeIndex item, but i don't know how to patch this definitely.
11
+ It's seems like a behavior that react-native is doing to start from the end of list, except we don't want this kind of RTL behavior as this list is "time based" and need to always stay LTR.
12
+ Except a visual jump on RTL layout.
13
+ */
8
14
  function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOnSidePress = false, containerProps, slideIndicatorContainerProps, scrollViewProps, onChange, onOverflow, IndicatorComponent = SlideIndicator, maxDurationOfTap, children, onAutoChange, onManualChange, }) {
9
15
  const [init, setInit] = useState(false);
10
16
  const [activeIndexState, setActiveIndexState] = useState(activeIndex);
@@ -25,17 +31,15 @@ function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOn
25
31
  }, [itemWidth]);
26
32
  useEffect(() => {
27
33
  // On init scroll to the active index prop location - if specified.
28
- if (init && activeIndex) {
34
+ if (init && typeof activeIndex === "number") {
29
35
  scrollToIndex(activeIndex, false);
30
36
  }
31
- // eslint-disable-next-line react-hooks/exhaustive-deps
32
- }, [init]);
37
+ }, [activeIndex, init, scrollToIndex]);
33
38
  useEffect(() => {
34
39
  if (scrollToIndex && typeof activeIndex === "number") {
35
- scrollToIndex(activeIndex);
40
+ scrollToIndex(activeIndex, false);
36
41
  }
37
- // eslint-disable-next-line react-hooks/exhaustive-deps
38
- }, [activeIndex]);
42
+ }, [activeIndex, scrollToIndex]);
39
43
  const onContentSizeChange = (contentWidth, contentHeight) => {
40
44
  dimensions.current = { contentWidth, contentHeight };
41
45
  setInit(true);
@@ -109,7 +113,10 @@ function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOn
109
113
  disableTimer.current = true;
110
114
  }, onScrollEndDrag: () => {
111
115
  disableTimer.current = false;
112
- }, pagingEnabled: Platform.OS !== "web", showsHorizontalScrollIndicator: false, scrollEventThrottle: 200, contentContainerStyle: { width: `${fullWidth}%` }, decelerationRate: "fast", onTouchStart: scrollOnSidePress ? onStartTap : undefined, onTouchEnd: scrollOnSidePress ? onEndTap : undefined }, scrollViewProps), React.Children.map(children, (child, index) => (React.createElement(Flex, { key: index, flex: 1 }, child)))),
116
+ }, pagingEnabled: Platform.OS !== "web", showsHorizontalScrollIndicator: false, scrollEventThrottle: 200, contentContainerStyle: {
117
+ width: `${fullWidth}%`,
118
+ flexDirection: I18nManager.isRTL && Platform.OS !== "ios" ? "row-reverse" : "row",
119
+ }, decelerationRate: "fast", onTouchStart: scrollOnSidePress ? onStartTap : undefined, onTouchEnd: scrollOnSidePress ? onEndTap : undefined }, scrollViewProps), React.Children.map(children, (child, index) => (React.createElement(Flex, { key: index, flex: 1 }, child)))),
113
120
  React.createElement(Flex, Object.assign({ my: 8 }, slideIndicatorContainerProps), React.isValidElement(IndicatorComponent) ? (IndicatorComponent) : (React.createElement(IndicatorComponent, { activeIndex: activeIndexState || 0, onChange: (index) => {
114
121
  scrollToIndex(index);
115
122
  setResetTimer({});
@@ -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;
@@ -17,6 +17,7 @@ const modalStyleOverrides = StyleSheet.create({
17
17
  flex: 1,
18
18
  justifyContent: "flex-end",
19
19
  margin: 0,
20
+ marginTop: 32,
20
21
  },
21
22
  safeContainer: {
22
23
  borderTopLeftRadius: 24,
@@ -2,6 +2,7 @@ import React, { useEffect, useMemo } from "react";
2
2
  import styled from "styled-components/native";
3
3
  import Animated, { useAnimatedStyle, withTiming, useSharedValue, Easing, } from "react-native-reanimated";
4
4
  import { Flex } from "../../Layout";
5
+ import { I18nManager } from "react-native";
5
6
  const ProgressBar = styled.View `
6
7
  background-color: ${(p) => p.theme.colors.primary.c100};
7
8
  border-radius: ${(p) => p.theme.radii[2]}px;
@@ -27,6 +28,10 @@ function StoryBar({ full = false, isActive, duration }) {
27
28
  }
28
29
  function StoriesIndicator({ activeIndex, slidesLength, duration }) {
29
30
  const storiesArray = useMemo(() => new Array(slidesLength).fill(0), [slidesLength]);
30
- return (React.createElement(Flex, { flexDirection: "row", alignItems: "stretch", width: "100%" }, storiesArray.map((_, storyIndex) => (React.createElement(StoryBar, { key: storyIndex, full: activeIndex > storyIndex, isActive: activeIndex === storyIndex, duration: duration })))));
31
+ return (React.createElement(Flex, { flexDirection: "row", alignItems: "stretch", width: "100%", style: I18nManager.isRTL
32
+ ? {
33
+ transform: [{ scaleX: -1 }],
34
+ }
35
+ : undefined }, storiesArray.map((_, storyIndex) => (React.createElement(StoryBar, { key: storyIndex, full: activeIndex > storyIndex, isActive: activeIndex === storyIndex, duration: duration })))));
31
36
  }
32
37
  export default React.memo(StoriesIndicator);
@@ -16,5 +16,5 @@ export interface BaseTextProps extends TextProps, BaseStyledProps, FontSizeProps
16
16
  uppercase?: boolean;
17
17
  children: React.ReactNode;
18
18
  }
19
- declare const Text: ({ children, bracket, ...props }: BaseTextProps) => JSX.Element;
19
+ declare const Text: ({ children, bracket, textAlign, ...props }: BaseTextProps) => JSX.Element;
20
20
  export default Text;
@@ -56,9 +56,9 @@ const BracketText = (_a) => {
56
56
  React.createElement(BracketRight, { fill: c, width: size, height: size })));
57
57
  };
58
58
  const Text = (_a) => {
59
- var { children, bracket } = _a, props = __rest(_a, ["children", "bracket"]);
59
+ var { children, bracket, textAlign = "left" } = _a, props = __rest(_a, ["children", "bracket", "textAlign"]);
60
60
  if (bracket)
61
61
  return React.createElement(BracketText, Object.assign({}, props), children);
62
- return React.createElement(Base, Object.assign({}, props), children);
62
+ return (React.createElement(Base, Object.assign({ textAlign: textAlign }, props), children));
63
63
  };
64
64
  export default Text;
@@ -3,6 +3,8 @@ export function getButtonColors(colors) {
3
3
  default: {
4
4
  primaryColor: colors.neutral.c100,
5
5
  secondaryColor: "rgba(0,0,255,0)",
6
+ pressedColor: "transparent",
7
+ pressedOutlineColor: "transparent",
6
8
  },
7
9
  disabled: {
8
10
  primaryColor: colors.neutral.c50,
@@ -3,6 +3,7 @@ import styled, { useTheme } from "styled-components/native";
3
3
  import { Svg, Path } from "react-native-svg";
4
4
  import FlexBox from "../../Layout/Flex";
5
5
  import { getColor } from "../../../styles";
6
+ import { I18nManager } from "react-native";
6
7
  const BracketContainer = styled(FlexBox).attrs({
7
8
  flexDirection: "column",
8
9
  position: "relative",
@@ -15,15 +16,22 @@ export const Bracket = ({ color, style, mb, mt }) => {
15
16
  React.createElement(Svg, { width: "17", height: "10", viewBox: "0 0 17 10" },
16
17
  React.createElement(Path, { d: "M16.8125 0H2.8125H0.8125V2V10H2.8125V2H16.8125V0Z", fill: fill }))));
17
18
  };
19
+ const RTLBracketManager = ({ children }) => {
20
+ return (React.createElement(FlexBox, { style: { transform: I18nManager.isRTL ? [{ scaleX: -1 }] : undefined } }, children));
21
+ };
18
22
  export const BracketTopLeft = ({ color }) => {
19
- return React.createElement(Bracket, { color: color });
23
+ return (React.createElement(RTLBracketManager, null,
24
+ React.createElement(Bracket, { color: color })));
20
25
  };
21
26
  export const BracketTopRight = ({ color }) => {
22
- return React.createElement(Bracket, { color: color, style: { transform: [{ scaleX: -1 }] } });
27
+ return (React.createElement(RTLBracketManager, null,
28
+ React.createElement(Bracket, { color: color, style: { transform: [{ scaleX: -1 }] } })));
23
29
  };
24
30
  export const BracketBottomLeft = ({ color }) => {
25
- return React.createElement(Bracket, { color: color, style: { transform: [{ scaleY: -1 }] } });
31
+ return (React.createElement(RTLBracketManager, null,
32
+ React.createElement(Bracket, { color: color, style: { transform: [{ scaleY: -1 }] } })));
26
33
  };
27
34
  export const BracketBottomRight = ({ color }) => {
28
- return React.createElement(Bracket, { color: color, style: { transform: [{ scale: -1 }] } });
35
+ return (React.createElement(RTLBracketManager, null,
36
+ React.createElement(Bracket, { color: color, style: { transform: [{ scale: -1 }] } })));
29
37
  };
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.12.0-next.0",
4
4
  "description": "Ledger Live - Mobile UI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -134,13 +134,13 @@
134
134
  "regenerator-runtime": "^0.13.9",
135
135
  "rimraf": "^3.0.2",
136
136
  "styled-components": "^5.3.3",
137
- "typescript": "^4.4.4",
138
- "victory": "^35.5.5",
139
- "webpack": "^4.46.0",
140
137
  "stylelint": "^14.9.1",
141
138
  "stylelint-config-recommended": "^8.0.0",
142
139
  "stylelint-config-styled-components": "^0.1.1",
143
- "stylelint-processor-styled-components": "^1.10.0"
140
+ "stylelint-processor-styled-components": "^1.10.0",
141
+ "typescript": "^4.4.4",
142
+ "victory": "^35.5.5",
143
+ "webpack": "^4.46.0"
144
144
  },
145
145
  "scripts": {
146
146
  "android": "expo start --android",