@ovotech/element-native 4.4.4 → 4.4.5-canary-7a3ddf3-320

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.
@@ -79,12 +79,11 @@ var SegmentedControls = function (_a) {
79
79
  }); }, [animatedX, animatedY, animatedWidth, animatedHeight]);
80
80
  return ((0, jsx_runtime_1.jsxs)(SegmentsContainer, __assign({ "$inline": inline, "$multipleRows": multipleRows }, rest, { children: [(0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: animatedBackgroundStyle }), segments.map(function (segment) {
81
81
  var _a, _b;
82
- return ((0, jsx_runtime_1.jsx)(SegmentButton_1.SegmentButton, { isSelected: activeSegment.key === segment.key, label: segment.label, accessibilityLabel: segment.accessibilityLabel, onPress: function (x, y, width) {
83
- setActiveSegment(segment);
82
+ return ((0, jsx_runtime_1.jsx)(SegmentButton_1.SegmentButton, { isSelected: activeSegment.key === segment.key, label: segment.label, accessibilityLabel: segment.accessibilityLabel, setAnimatedValues: function (x, y, width) {
84
83
  animatedX.value = (0, react_native_reanimated_1.withSpring)(x, springSettings);
85
84
  animatedY.value = (0, react_native_reanimated_1.withSpring)(y, springSettings);
86
85
  animatedWidth.value = width;
87
- }, onLayout: function (width, height, x, y) {
86
+ }, onPress: function () { return setActiveSegment(segment); }, onLayout: function (width, height, x, y) {
88
87
  if (activeSegment.key === segment.key) {
89
88
  animatedX.value = x;
90
89
  // (adrian.pop) - I couldn't figure out how to make the positioning work once the
@@ -1,7 +1,8 @@
1
1
  type SegmentButtonProps = {
2
2
  isSelected: boolean;
3
3
  label: string;
4
- onPress: (x: number, y: number, width: number) => void;
4
+ setAnimatedValues: (x: number, y: number, width: number) => void;
5
+ onPress: (...args: any[]) => void;
5
6
  onLayout: (width: number, height: number, x: number, y: number) => void;
6
7
  accessibilityLabel?: string;
7
8
  inline?: boolean;
@@ -10,5 +11,5 @@ type SegmentButtonProps = {
10
11
  testID?: string;
11
12
  segmentCount: number;
12
13
  };
13
- export declare const SegmentButton: ({ accessibilityLabel, inline, isSelected, label, multipleRows, onLayout, onPress, segmentCount, size, testID, }: SegmentButtonProps) => JSX.Element;
14
+ export declare const SegmentButton: ({ accessibilityLabel, inline, isSelected, label, multipleRows, onLayout, onPress, setAnimatedValues, segmentCount, size, testID, }: SegmentButtonProps) => JSX.Element;
14
15
  export {};
@@ -35,7 +35,7 @@ var styled_native_1 = __importDefault(require("../../../styled.native"));
35
35
  var P_1 = require("../../P");
36
36
  var AnimatedP = react_native_reanimated_1.default.createAnimatedComponent(P_1.P);
37
37
  var SegmentButton = function (_a) {
38
- var accessibilityLabel = _a.accessibilityLabel, inline = _a.inline, isSelected = _a.isSelected, label = _a.label, multipleRows = _a.multipleRows, onLayout = _a.onLayout, onPress = _a.onPress, segmentCount = _a.segmentCount, _b = _a.size, size = _b === void 0 ? 'large' : _b, testID = _a.testID;
38
+ var accessibilityLabel = _a.accessibilityLabel, inline = _a.inline, isSelected = _a.isSelected, label = _a.label, multipleRows = _a.multipleRows, onLayout = _a.onLayout, onPress = _a.onPress, setAnimatedValues = _a.setAnimatedValues, segmentCount = _a.segmentCount, _b = _a.size, size = _b === void 0 ? 'large' : _b, testID = _a.testID;
39
39
  var xRef = (0, react_1.useRef)(0);
40
40
  var yRef = (0, react_1.useRef)(0);
41
41
  var widthRef = (0, react_1.useRef)(0);
@@ -57,6 +57,17 @@ var SegmentButton = function (_a) {
57
57
  (0, react_1.useEffect)(function () {
58
58
  fontWeightAnim.value = (0, react_native_reanimated_1.withTiming)(isSelected ? 1 : 0);
59
59
  }, [fontWeightAnim, isSelected]);
60
+ (0, react_1.useEffect)(function () {
61
+ if (!isSelected) {
62
+ return;
63
+ }
64
+ setAnimatedValues(xRef.current,
65
+ // (adrian.pop) - I couldn't figure out how to make the positioning work once the
66
+ // choices go on the second row. The only way I could get it to work
67
+ // was to hardcode the denominator to 3 for the single row ones
68
+ // and 1.1 for the multiple row ones.
69
+ yRef.current - heightRef.current / (multipleRows ? 1.1 : 3), widthRef.current);
70
+ }, [isSelected]);
60
71
  var handleLayout = function (event) {
61
72
  var _a = event.nativeEvent.layout, width = _a.width, height = _a.height, x = _a.x, y = _a.y;
62
73
  xRef.current = x;
@@ -65,15 +76,7 @@ var SegmentButton = function (_a) {
65
76
  widthRef.current = width;
66
77
  onLayout(width, height, x, y);
67
78
  };
68
- var handlePress = function () {
69
- onPress(xRef.current,
70
- // (adrian.pop) - I couldn't figure out how to make the positioning work once the
71
- // choices go on the second row. The only way I could get it to work
72
- // was to hardcode the denominator to 3 for the single row ones
73
- // and 1.1 for the multiple row ones.
74
- yRef.current - heightRef.current / (multipleRows ? 1.1 : 3), widthRef.current);
75
- };
76
- return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onLayout: handleLayout, onPress: handlePress, accessible: true, accessibilityRole: "checkbox", accessibilityState: { selected: isSelected }, accessibilityLabel: accessibilityLabel || label, hitSlop: {
79
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onLayout: handleLayout, onPress: onPress, accessible: true, accessibilityRole: "checkbox", accessibilityState: { selected: isSelected }, accessibilityLabel: accessibilityLabel || label, hitSlop: {
77
80
  top: hitslopVal,
78
81
  bottom: hitslopVal,
79
82
  }, style: {
@@ -53,12 +53,11 @@ export var SegmentedControls = function (_a) {
53
53
  }); }, [animatedX, animatedY, animatedWidth, animatedHeight]);
54
54
  return (_jsxs(SegmentsContainer, __assign({ "$inline": inline, "$multipleRows": multipleRows }, rest, { children: [_jsx(Animated.View, { style: animatedBackgroundStyle }), segments.map(function (segment) {
55
55
  var _a, _b;
56
- return (_jsx(SegmentButton, { isSelected: activeSegment.key === segment.key, label: segment.label, accessibilityLabel: segment.accessibilityLabel, onPress: function (x, y, width) {
57
- setActiveSegment(segment);
56
+ return (_jsx(SegmentButton, { isSelected: activeSegment.key === segment.key, label: segment.label, accessibilityLabel: segment.accessibilityLabel, setAnimatedValues: function (x, y, width) {
58
57
  animatedX.value = withSpring(x, springSettings);
59
58
  animatedY.value = withSpring(y, springSettings);
60
59
  animatedWidth.value = width;
61
- }, onLayout: function (width, height, x, y) {
60
+ }, onPress: function () { return setActiveSegment(segment); }, onLayout: function (width, height, x, y) {
62
61
  if (activeSegment.key === segment.key) {
63
62
  animatedX.value = x;
64
63
  // (adrian.pop) - I couldn't figure out how to make the positioning work once the
@@ -6,7 +6,7 @@ import styled from '../../../styled.native';
6
6
  import { P } from '../../P';
7
7
  var AnimatedP = Animated.createAnimatedComponent(P);
8
8
  export var SegmentButton = function (_a) {
9
- var accessibilityLabel = _a.accessibilityLabel, inline = _a.inline, isSelected = _a.isSelected, label = _a.label, multipleRows = _a.multipleRows, onLayout = _a.onLayout, onPress = _a.onPress, segmentCount = _a.segmentCount, _b = _a.size, size = _b === void 0 ? 'large' : _b, testID = _a.testID;
9
+ var accessibilityLabel = _a.accessibilityLabel, inline = _a.inline, isSelected = _a.isSelected, label = _a.label, multipleRows = _a.multipleRows, onLayout = _a.onLayout, onPress = _a.onPress, setAnimatedValues = _a.setAnimatedValues, segmentCount = _a.segmentCount, _b = _a.size, size = _b === void 0 ? 'large' : _b, testID = _a.testID;
10
10
  var xRef = useRef(0);
11
11
  var yRef = useRef(0);
12
12
  var widthRef = useRef(0);
@@ -28,6 +28,17 @@ export var SegmentButton = function (_a) {
28
28
  useEffect(function () {
29
29
  fontWeightAnim.value = withTiming(isSelected ? 1 : 0);
30
30
  }, [fontWeightAnim, isSelected]);
31
+ useEffect(function () {
32
+ if (!isSelected) {
33
+ return;
34
+ }
35
+ setAnimatedValues(xRef.current,
36
+ // (adrian.pop) - I couldn't figure out how to make the positioning work once the
37
+ // choices go on the second row. The only way I could get it to work
38
+ // was to hardcode the denominator to 3 for the single row ones
39
+ // and 1.1 for the multiple row ones.
40
+ yRef.current - heightRef.current / (multipleRows ? 1.1 : 3), widthRef.current);
41
+ }, [isSelected]);
31
42
  var handleLayout = function (event) {
32
43
  var _a = event.nativeEvent.layout, width = _a.width, height = _a.height, x = _a.x, y = _a.y;
33
44
  xRef.current = x;
@@ -36,15 +47,7 @@ export var SegmentButton = function (_a) {
36
47
  widthRef.current = width;
37
48
  onLayout(width, height, x, y);
38
49
  };
39
- var handlePress = function () {
40
- onPress(xRef.current,
41
- // (adrian.pop) - I couldn't figure out how to make the positioning work once the
42
- // choices go on the second row. The only way I could get it to work
43
- // was to hardcode the denominator to 3 for the single row ones
44
- // and 1.1 for the multiple row ones.
45
- yRef.current - heightRef.current / (multipleRows ? 1.1 : 3), widthRef.current);
46
- };
47
- return (_jsx(Pressable, { onLayout: handleLayout, onPress: handlePress, accessible: true, accessibilityRole: "checkbox", accessibilityState: { selected: isSelected }, accessibilityLabel: accessibilityLabel || label, hitSlop: {
50
+ return (_jsx(Pressable, { onLayout: handleLayout, onPress: onPress, accessible: true, accessibilityRole: "checkbox", accessibilityState: { selected: isSelected }, accessibilityLabel: accessibilityLabel || label, hitSlop: {
48
51
  top: hitslopVal,
49
52
  bottom: hitslopVal,
50
53
  }, style: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovotech/element-native",
3
- "version": "4.4.4",
3
+ "version": "4.4.5-canary-7a3ddf3-320",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,10 +14,10 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@backpackapp-io/react-native-toast": "^0.10.0",
17
+ "@ovotech/element-core": "3.2.0-canary-7a3ddf3-320",
17
18
  "deepmerge": "^4.2.2",
18
19
  "lodash.groupby": "^4.6.0",
19
- "react-native-reanimated-carousel": "^3.5.1",
20
- "@ovotech/element-core": "3.2.0"
20
+ "react-native-reanimated-carousel": "^3.5.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@babel/core": "^7.11.5",