@fluentui-react-native/experimental-activity-indicator 0.3.27 → 0.5.2

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.
Files changed (62) hide show
  1. package/CHANGELOG.json +90 -1
  2. package/CHANGELOG.md +39 -2
  3. package/lib/ActivityIndicator.android.d.ts +4 -0
  4. package/lib/ActivityIndicator.android.d.ts.map +1 -0
  5. package/lib/ActivityIndicator.android.js +4 -0
  6. package/lib/ActivityIndicator.android.js.map +1 -0
  7. package/lib/ActivityIndicator.d.ts +3 -5
  8. package/lib/ActivityIndicator.d.ts.map +1 -1
  9. package/lib/ActivityIndicator.ios.d.ts +4 -0
  10. package/lib/ActivityIndicator.ios.d.ts.map +1 -0
  11. package/lib/ActivityIndicator.ios.js +4 -0
  12. package/lib/ActivityIndicator.ios.js.map +1 -0
  13. package/lib/ActivityIndicator.js +3 -116
  14. package/lib/ActivityIndicator.js.map +1 -1
  15. package/lib/ActivityIndicator.mobile.d.ts +6 -0
  16. package/lib/ActivityIndicator.mobile.d.ts.map +1 -0
  17. package/lib/ActivityIndicator.mobile.js +117 -0
  18. package/lib/ActivityIndicator.mobile.js.map +1 -0
  19. package/lib/ActivityIndicator.styling.d.ts +5 -2
  20. package/lib/ActivityIndicator.styling.d.ts.map +1 -1
  21. package/lib/ActivityIndicator.styling.js +45 -0
  22. package/lib/ActivityIndicator.styling.js.map +1 -1
  23. package/lib/ActivityIndicator.types.d.ts +17 -9
  24. package/lib/ActivityIndicator.types.d.ts.map +1 -1
  25. package/lib/CoreActivityIndicator.d.ts +8 -0
  26. package/lib/CoreActivityIndicator.d.ts.map +1 -0
  27. package/lib/CoreActivityIndicator.js +27 -0
  28. package/lib/CoreActivityIndicator.js.map +1 -0
  29. package/lib-commonjs/ActivityIndicator.android.d.ts +4 -0
  30. package/lib-commonjs/ActivityIndicator.android.d.ts.map +1 -0
  31. package/lib-commonjs/ActivityIndicator.android.js +7 -0
  32. package/lib-commonjs/ActivityIndicator.android.js.map +1 -0
  33. package/lib-commonjs/ActivityIndicator.d.ts +3 -5
  34. package/lib-commonjs/ActivityIndicator.d.ts.map +1 -1
  35. package/lib-commonjs/ActivityIndicator.ios.d.ts +4 -0
  36. package/lib-commonjs/ActivityIndicator.ios.d.ts.map +1 -0
  37. package/lib-commonjs/ActivityIndicator.ios.js +7 -0
  38. package/lib-commonjs/ActivityIndicator.ios.js.map +1 -0
  39. package/lib-commonjs/ActivityIndicator.js +4 -116
  40. package/lib-commonjs/ActivityIndicator.js.map +1 -1
  41. package/lib-commonjs/ActivityIndicator.mobile.d.ts +6 -0
  42. package/lib-commonjs/ActivityIndicator.mobile.d.ts.map +1 -0
  43. package/lib-commonjs/ActivityIndicator.mobile.js +119 -0
  44. package/lib-commonjs/ActivityIndicator.mobile.js.map +1 -0
  45. package/lib-commonjs/ActivityIndicator.styling.d.ts +5 -2
  46. package/lib-commonjs/ActivityIndicator.styling.d.ts.map +1 -1
  47. package/lib-commonjs/ActivityIndicator.styling.js +49 -0
  48. package/lib-commonjs/ActivityIndicator.styling.js.map +1 -1
  49. package/lib-commonjs/ActivityIndicator.types.d.ts +17 -9
  50. package/lib-commonjs/ActivityIndicator.types.d.ts.map +1 -1
  51. package/lib-commonjs/CoreActivityIndicator.d.ts +8 -0
  52. package/lib-commonjs/CoreActivityIndicator.d.ts.map +1 -0
  53. package/lib-commonjs/CoreActivityIndicator.js +29 -0
  54. package/lib-commonjs/CoreActivityIndicator.js.map +1 -0
  55. package/package.json +7 -6
  56. package/src/ActivityIndicator.android.tsx +3 -0
  57. package/src/ActivityIndicator.ios.tsx +3 -0
  58. package/src/ActivityIndicator.mobile.tsx +119 -0
  59. package/src/ActivityIndicator.styling.tsx +48 -3
  60. package/src/ActivityIndicator.tsx +3 -119
  61. package/src/ActivityIndicator.types.tsx +19 -10
  62. package/src/CoreActivityIndicator.tsx +22 -0
@@ -0,0 +1,119 @@
1
+ /** @jsx withSlots */
2
+ import { useRef, useEffect, useCallback } from 'react';
3
+ import { Animated, Easing, View } from 'react-native';
4
+ import { Svg, Path } from 'react-native-svg';
5
+ import { compose, mergeProps, withSlots, UseSlots, buildUseStyling } from '@fluentui-react-native/framework';
6
+ import { activityIndicatorName, ActivityIndicatorProps, FluentActivityIndicatorType } from './ActivityIndicator.types';
7
+ import { diameterSizeMap, lineThicknessSizeMap, stylingSettings } from './ActivityIndicator.styling';
8
+
9
+ const getActivityIndicatorPath = (diameter: number, width: number, color: string) => {
10
+ const start = {
11
+ x: width / 2,
12
+ y: diameter / 2,
13
+ };
14
+ const innerRadius = diameter / 2 - width / 2;
15
+ const path = `M${start.x} ${start.y} a${innerRadius} ${innerRadius} 0 1 1 ${innerRadius} ${innerRadius}`;
16
+
17
+ return <Path d={path} stroke={color} strokeWidth={width} strokeLinecap="round" />;
18
+ };
19
+
20
+ export const AnimatedSvg = Animated.createAnimatedComponent(Svg);
21
+ const useStyling = buildUseStyling(stylingSettings);
22
+ export const ActivityIndicator = compose<FluentActivityIndicatorType>({
23
+ displayName: activityIndicatorName,
24
+ ...stylingSettings,
25
+ slots: {
26
+ root: View,
27
+ svg: AnimatedSvg,
28
+ },
29
+ render: (props: ActivityIndicatorProps, useSlots: UseSlots<FluentActivityIndicatorType>) => {
30
+ const Slots = useSlots(props);
31
+ const slotProps = useStyling(props);
32
+
33
+ const animating = props.animating != undefined ? props.animating : true;
34
+ const hidesWhenStopped = props.hidesWhenStopped != undefined ? props.hidesWhenStopped : true;
35
+ // React Native ActivityIndicator still takes up space when hidden, so to perfectly match would use opacity
36
+ // hiding opacity makes the screen reader on iOS and Android skip over it
37
+ const hideOpacity = animating == false && hidesWhenStopped == true ? 0 : 1;
38
+
39
+ const rotationAngle = useRef(new Animated.Value(0)).current;
40
+
41
+ const rotationAnimation = useRef<Animated.CompositeAnimation | undefined>(undefined);
42
+
43
+ /**
44
+ * https://github.com/facebook/react-native/pull/29585
45
+ * For Animated.loop() to work with the native driver, React Native needs this fix.
46
+ * It's only available in React Native 0.66+, and React Native macOS 0.62+
47
+ * To workaround this, let's just rerun the loop everytime the animation finishes
48
+ */
49
+ const startRotation = useCallback(() => {
50
+ if (rotationAnimation.current) {
51
+ rotationAngle.setValue(0);
52
+ rotationAnimation.current.reset();
53
+ rotationAnimation.current.start((result: Animated.EndResult) => {
54
+ if (result.finished) {
55
+ startRotation();
56
+ }
57
+ });
58
+ }
59
+ }, [rotationAngle, animating]);
60
+
61
+ const stopRotation = () => {
62
+ if (rotationAnimation.current) {
63
+ rotationAnimation.current.stop();
64
+ }
65
+ };
66
+
67
+ useEffect(() => {
68
+ if (rotationAnimation.current === undefined) {
69
+ rotationAnimation.current = Animated.sequence([
70
+ Animated.timing(rotationAngle, {
71
+ toValue: 359,
72
+ duration: 750,
73
+ useNativeDriver: true,
74
+ easing: Easing.linear,
75
+ }),
76
+ ]);
77
+ }
78
+
79
+ if (animating) {
80
+ startRotation();
81
+ } else {
82
+ stopRotation();
83
+ }
84
+ }, [animating, hidesWhenStopped, rotationAngle]);
85
+
86
+ const interpolateSpin = rotationAngle.interpolate({
87
+ inputRange: [0, 359],
88
+ outputRange: ['0deg', '359deg'],
89
+ });
90
+
91
+ const path = getActivityIndicatorPath(
92
+ diameterSizeMap[slotProps.root.size],
93
+ lineThicknessSizeMap[slotProps.root.lineThickness],
94
+ slotProps.root.activityIndicatorColor,
95
+ );
96
+
97
+ // perspective is needed for animations to work on Android. See https://reactnative.dev/docs/animations#bear-in-mind
98
+ const animatedSvgProps = {
99
+ style: {
100
+ transform: [{ rotateZ: interpolateSpin }, { perspective: 10 }],
101
+ },
102
+ };
103
+
104
+ const otherRootProps = {
105
+ style: {
106
+ opacity: hideOpacity,
107
+ },
108
+ accessibilityState: { busy: animating },
109
+ };
110
+ return (rest: ActivityIndicatorProps) => {
111
+ const { ...mergedProps } = mergeProps(props, rest, otherRootProps);
112
+ return (
113
+ <Slots.root {...mergedProps}>
114
+ <Slots.svg {...animatedSvgProps}>{path}</Slots.svg>
115
+ </Slots.root>
116
+ );
117
+ };
118
+ },
119
+ });
@@ -1,11 +1,14 @@
1
1
  import { UseStylingOptions, buildProps } from '@fluentui-react-native/framework';
2
- import { Appearance } from 'react-native';
2
+ import { ActivityIndicatorProps as CoreActivityIndicatorProps, Appearance } from 'react-native';
3
3
  import {
4
4
  activityIndicatorName,
5
5
  ActivityIndicatorProps,
6
- ActivityIndicatorSlotProps,
6
+ FluentActivityIndicatorSlotProps,
7
7
  ActivityIndicatorTokens,
8
+ CoreActivityIndicatorSlotProps,
9
+ ActivityIndicatorSize,
8
10
  } from './ActivityIndicator.types';
11
+ import assertNever from 'assert-never';
9
12
 
10
13
  export const diameterSizeMap: { [key: string]: number } = {
11
14
  xSmall: 12,
@@ -22,7 +25,29 @@ export const lineThicknessSizeMap: { [key: string]: number } = {
22
25
  xLarge: 4,
23
26
  };
24
27
 
25
- export const stylingSettings: UseStylingOptions<ActivityIndicatorProps, ActivityIndicatorSlotProps, ActivityIndicatorTokens> = {
28
+ // Size coversion ramp from the Fluent ActivityIndicator size to the RN ActivityIndicator.
29
+ export function coreSizeFromFluentSize(fluentSize: ActivityIndicatorSize): CoreActivityIndicatorProps['size'] {
30
+ if (typeof fluentSize === 'undefined') {
31
+ return fluentSize;
32
+ }
33
+
34
+ switch (fluentSize) {
35
+ case 'xSmall':
36
+ return 'small';
37
+ case 'small':
38
+ return 'small';
39
+ case 'medium':
40
+ return 'small';
41
+ case 'large':
42
+ return 'large';
43
+ case 'xLarge':
44
+ return 'large';
45
+ default:
46
+ assertNever(fluentSize);
47
+ }
48
+ }
49
+
50
+ export const stylingSettings: UseStylingOptions<ActivityIndicatorProps, FluentActivityIndicatorSlotProps, ActivityIndicatorTokens> = {
26
51
  tokens: [
27
52
  () => ({
28
53
  activityIndicatorColor: Appearance.getColorScheme() === 'light' ? '#BDBDBD' : '#666666',
@@ -56,3 +81,23 @@ export const stylingSettings: UseStylingOptions<ActivityIndicatorProps, Activity
56
81
  ),
57
82
  },
58
83
  };
84
+
85
+ // Minimal styling settings for the RN Core ActivityIndicator
86
+ export const coreStylingSettings: UseStylingOptions<ActivityIndicatorProps, CoreActivityIndicatorSlotProps, ActivityIndicatorTokens> = {
87
+ tokens: [
88
+ () => ({
89
+ size: 'small',
90
+ }),
91
+ activityIndicatorName,
92
+ ],
93
+ tokensThatAreAlsoProps: 'all',
94
+ slotProps: {
95
+ root: buildProps(
96
+ (tokens: ActivityIndicatorTokens) => ({
97
+ color: tokens.activityIndicatorColor,
98
+ ...(tokens.size && { size: coreSizeFromFluentSize(tokens.size) }), // Only pass in the prop if defined
99
+ }),
100
+ ['activityIndicatorColor', 'size'],
101
+ ),
102
+ },
103
+ };
@@ -1,119 +1,3 @@
1
- /** @jsx withSlots */
2
- import { useRef, useEffect, useCallback } from 'react';
3
- import { Animated, Easing, View } from 'react-native';
4
- import { Svg, Path } from 'react-native-svg';
5
- import { compose, mergeProps, withSlots, UseSlots, buildUseStyling } from '@fluentui-react-native/framework';
6
- import { activityIndicatorName, ActivityIndicatorProps, ActivityIndicatorType } from './ActivityIndicator.types';
7
- import { diameterSizeMap, lineThicknessSizeMap, stylingSettings } from './ActivityIndicator.styling';
8
-
9
- const getActivityIndicatorPath = (diameter: number, width: number, color: string) => {
10
- const start = {
11
- x: width / 2,
12
- y: diameter / 2,
13
- };
14
- const innerRadius = diameter / 2 - width / 2;
15
- const path = `M${start.x} ${start.y} a${innerRadius} ${innerRadius} 0 1 1 ${innerRadius} ${innerRadius}`;
16
-
17
- return <Path d={path} stroke={color} strokeWidth={width} strokeLinecap="round" />;
18
- };
19
-
20
- export const AnimatedSvg = Animated.createAnimatedComponent(Svg);
21
- const useStyling = buildUseStyling(stylingSettings);
22
- export const ActivityIndicator = compose<ActivityIndicatorType>({
23
- displayName: activityIndicatorName,
24
- ...stylingSettings,
25
- slots: {
26
- root: View,
27
- svg: AnimatedSvg,
28
- },
29
- render: (props: ActivityIndicatorProps, useSlots: UseSlots<ActivityIndicatorType>) => {
30
- const Slots = useSlots(props);
31
- const slotProps = useStyling(props);
32
-
33
- const animating = props.animating != undefined ? props.animating : true;
34
- const hidesWhenStopped = props.hidesWhenStopped != undefined ? props.hidesWhenStopped : true;
35
- // React Native ActivityIndicator still takes up space when hidden, so to perfectly match would use opacity
36
- // hiding opacity makes the screen reader on iOS and Android skip over it
37
- const hideOpacity = animating == false && hidesWhenStopped == true ? 0 : 1;
38
-
39
- const rotationAngle = useRef(new Animated.Value(0)).current;
40
-
41
- const rotationAnimation = useRef<Animated.CompositeAnimation | undefined>(undefined);
42
-
43
- /**
44
- * https://github.com/facebook/react-native/pull/29585
45
- * For Animated.loop() to work with the native driver, React Native needs this fix.
46
- * It's only available in React Native 0.66+, and React Native macOS 0.62+
47
- * To workaround this, let's just rerun the loop everytime the animation finishes
48
- */
49
- const startRotation = useCallback(() => {
50
- if (rotationAnimation.current) {
51
- rotationAngle.setValue(0);
52
- rotationAnimation.current.reset();
53
- rotationAnimation.current.start((result: Animated.EndResult) => {
54
- if (result.finished) {
55
- startRotation();
56
- }
57
- });
58
- }
59
- }, [rotationAngle, animating]);
60
-
61
- const stopRotation = () => {
62
- if (rotationAnimation.current) {
63
- rotationAnimation.current.stop();
64
- }
65
- };
66
-
67
- useEffect(() => {
68
- if (rotationAnimation.current === undefined) {
69
- rotationAnimation.current = Animated.sequence([
70
- Animated.timing(rotationAngle, {
71
- toValue: 359,
72
- duration: 750,
73
- useNativeDriver: true,
74
- easing: Easing.linear,
75
- }),
76
- ]);
77
- }
78
-
79
- if (animating) {
80
- startRotation();
81
- } else {
82
- stopRotation();
83
- }
84
- }, [animating, hidesWhenStopped, rotationAngle]);
85
-
86
- const interpolateSpin = rotationAngle.interpolate({
87
- inputRange: [0, 359],
88
- outputRange: ['0deg', '359deg'],
89
- });
90
-
91
- const path = getActivityIndicatorPath(
92
- diameterSizeMap[slotProps.root.size],
93
- lineThicknessSizeMap[slotProps.root.lineThickness],
94
- slotProps.root.activityIndicatorColor,
95
- );
96
-
97
- // perspective is needed for animations to work on Android. See https://reactnative.dev/docs/animations#bear-in-mind
98
- const animatedSvgProps = {
99
- style: {
100
- transform: [{ rotateZ: interpolateSpin }, { perspective: 10 }],
101
- },
102
- };
103
-
104
- const otherRootProps = {
105
- style: {
106
- opacity: hideOpacity,
107
- },
108
- accessibilityState: { busy: animating },
109
- };
110
- return (rest: ActivityIndicatorProps) => {
111
- const { ...mergedProps } = mergeProps(props, rest, otherRootProps);
112
- return (
113
- <Slots.root {...mergedProps}>
114
- <Slots.svg {...animatedSvgProps}>{path}</Slots.svg>
115
- </Slots.root>
116
- );
117
- };
118
- },
119
- });
1
+ import { ActivityIndicator } from './CoreActivityIndicator';
2
+ export { ActivityIndicator } from './CoreActivityIndicator';
3
+ export default ActivityIndicator;
@@ -1,9 +1,9 @@
1
- import { Animated, ViewProps } from 'react-native';
1
+ import { Animated, ActivityIndicatorProps as CoreActivityIndicatorProps } from 'react-native';
2
2
  import { SvgProps } from 'react-native-svg';
3
3
 
4
4
  export const activityIndicatorName = 'ActivityIndicator';
5
5
  /**
6
- * Specifies the possible sizes of the ActivityIndicator
6
+ * Specifies the possible sizes of the ActivityIndicator.
7
7
  */
8
8
  export type ActivityIndicatorSize = 'xSmall' | 'small' | 'medium' | 'large' | 'xLarge';
9
9
 
@@ -25,12 +25,7 @@ export interface ActivityIndicatorTokens {
25
25
  size?: ActivityIndicatorSize;
26
26
  }
27
27
 
28
- export interface ActivityIndicatorSlotProps {
29
- root: ViewProps & ActivityIndicatorTokens;
30
- svg: Animated.AnimatedProps<SvgProps>;
31
- }
32
-
33
- export interface ActivityIndicatorProps extends ActivityIndicatorTokens, ViewProps {
28
+ export interface ActivityIndicatorProps extends ActivityIndicatorTokens, Omit<CoreActivityIndicatorProps, 'size'> {
34
29
  /**
35
30
  * ActivityIndicator animating or not
36
31
  * @defaultValue 'true'
@@ -43,8 +38,22 @@ export interface ActivityIndicatorProps extends ActivityIndicatorTokens, ViewPro
43
38
  hidesWhenStopped?: boolean;
44
39
  }
45
40
 
46
- export interface ActivityIndicatorType {
41
+ export interface FluentActivityIndicatorSlotProps {
42
+ root: ActivityIndicatorProps;
43
+ svg: Animated.AnimatedProps<SvgProps>;
44
+ }
45
+ export interface FluentActivityIndicatorType {
46
+ props: ActivityIndicatorProps;
47
+ slotProps: FluentActivityIndicatorSlotProps;
48
+ tokens: ActivityIndicatorTokens;
49
+ }
50
+
51
+ export interface CoreActivityIndicatorSlotProps {
52
+ root: CoreActivityIndicatorProps;
53
+ }
54
+
55
+ export interface CoreActivityIndicatorType {
47
56
  props: ActivityIndicatorProps;
48
- slotProps: ActivityIndicatorSlotProps;
57
+ slotProps: CoreActivityIndicatorSlotProps;
49
58
  tokens: ActivityIndicatorTokens;
50
59
  }
@@ -0,0 +1,22 @@
1
+ /** @jsx withSlots */
2
+
3
+ import { ActivityIndicator as CoreActivityIndicator } from 'react-native';
4
+ import { activityIndicatorName, CoreActivityIndicatorType, ActivityIndicatorProps } from './ActivityIndicator.types';
5
+ import { coreStylingSettings } from './ActivityIndicator.styling';
6
+ import { compose, withSlots, UseSlots } from '@fluentui-react-native/framework';
7
+
8
+ /**
9
+ * Wrapper around React Native Core's ActivityIndicator for platforms we do not
10
+ * have a custom FluentUI React Native ActivityIndicator defined.
11
+ */
12
+ export const ActivityIndicator = compose<CoreActivityIndicatorType>({
13
+ displayName: activityIndicatorName,
14
+ ...coreStylingSettings,
15
+ slots: {
16
+ root: CoreActivityIndicator,
17
+ },
18
+ render: (props: ActivityIndicatorProps, useSlots: UseSlots<CoreActivityIndicatorType>) => {
19
+ const Slots = useSlots(props);
20
+ return () => <Slots.root />;
21
+ },
22
+ });