@fluentui-react-native/experimental-shadow 0.2.69 → 0.2.71

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.
package/src/Shadow.tsx CHANGED
@@ -1,13 +1,15 @@
1
1
  import * as React from 'react';
2
2
  import type { ViewStyle } from 'react-native';
3
3
  import { View } from 'react-native';
4
- import type { ShadowProps } from './Shadow.types';
5
- import { shadowName } from './Shadow.types';
4
+
6
5
  import { mergeProps, stagedComponent } from '@fluentui-react-native/framework';
7
- import { getShadowTokenStyleSet } from './shadowStyle';
8
6
  import { memoize } from '@fluentui-react-native/framework';
9
7
  import type { ShadowToken } from '@fluentui-react-native/theme-types';
10
8
 
9
+ import type { ShadowProps } from './Shadow.types';
10
+ import { shadowName } from './Shadow.types';
11
+ import { getShadowTokenStyleSet } from './shadowStyle';
12
+
11
13
  export const Shadow = stagedComponent((props: ShadowProps) => {
12
14
  return (final: ShadowProps, children: React.ReactNode) => {
13
15
  if (!props.shadowToken) {
@@ -39,6 +41,12 @@ const getStylePropsForShadowViews = memoize(getStylePropsForShadowViewsWorker);
39
41
  function getStylePropsForShadowViewsWorker(childStyleProps: ViewStyle = {}, shadowToken: ShadowToken) {
40
42
  const shadowTokenStyleSet = getShadowTokenStyleSet(shadowToken);
41
43
 
44
+ if (__DEV__) {
45
+ if (!childStyleProps.backgroundColor) {
46
+ console.warn('The View that the Shadow is set on must have a background color set');
47
+ }
48
+ }
49
+
42
50
  const {
43
51
  borderBottomWidth,
44
52
  borderEndWidth,
@@ -83,68 +91,65 @@ function getStylePropsForShadowViewsWorker(childStyleProps: ViewStyle = {}, shad
83
91
  ...restOfChildStyleProps
84
92
  } = childStyleProps;
85
93
 
86
- if (__DEV__) {
87
- if (!childStyleProps.backgroundColor) {
88
- console.warn('The View that the Shadow is set on must have a background color set');
89
- }
90
- }
94
+ // Remove undefined properties, otherwise every prop will be added and be set to
95
+ // undefined, which can cause unexpected behaviour with some of the styles
96
+ const innerStyle = removeUndefinedProperties({
97
+ borderBottomWidth,
98
+ borderEndWidth,
99
+ borderLeftWidth,
100
+ borderRightWidth,
101
+ borderStartWidth,
102
+ borderTopWidth,
103
+ borderWidth,
91
104
 
92
- return {
93
- inner: {
94
- style: {
95
- borderBottomWidth,
96
- borderEndWidth,
97
- borderLeftWidth,
98
- borderRightWidth,
99
- borderStartWidth,
100
- borderTopWidth,
101
- borderWidth,
102
-
103
- padding,
104
- paddingBottom,
105
- paddingEnd,
106
- paddingHorizontal,
107
- paddingLeft,
108
- paddingRight,
109
- paddingStart,
110
- paddingTop,
111
- paddingVertical,
112
-
113
- alignItems,
114
-
115
- flexWrap,
116
- flexDirection,
117
-
118
- ...shadowTokenStyleSet.key,
119
- ...restOfChildStyleProps,
120
- },
121
- },
122
- outer: {
123
- style: {
124
- margin,
125
- marginBottom,
126
- marginEnd,
127
- marginHorizontal,
128
- marginLeft,
129
- marginRight,
130
- marginStart,
131
- marginTop,
132
- marginVertical,
133
-
134
- start,
135
- end,
136
- left,
137
- right,
138
- top,
139
- bottom,
140
-
141
- ...shadowTokenStyleSet.ambient,
142
- ...restOfChildStyleProps,
143
- },
144
- },
145
- };
105
+ padding,
106
+ paddingBottom,
107
+ paddingEnd,
108
+ paddingHorizontal,
109
+ paddingLeft,
110
+ paddingRight,
111
+ paddingStart,
112
+ paddingTop,
113
+ paddingVertical,
114
+
115
+ alignItems,
116
+
117
+ flexWrap,
118
+ flexDirection,
119
+
120
+ ...shadowTokenStyleSet.key,
121
+ ...restOfChildStyleProps,
122
+ });
123
+
124
+ const outerStyle = removeUndefinedProperties({
125
+ margin,
126
+ marginBottom,
127
+ marginEnd,
128
+ marginHorizontal,
129
+ marginLeft,
130
+ marginRight,
131
+ marginStart,
132
+ marginTop,
133
+ marginVertical,
134
+
135
+ start,
136
+ end,
137
+ left,
138
+ right,
139
+ top,
140
+ bottom,
141
+
142
+ ...shadowTokenStyleSet.ambient,
143
+ ...restOfChildStyleProps,
144
+ });
145
+
146
+ return { inner: { style: innerStyle }, outer: { style: outerStyle } };
146
147
  }
147
148
 
149
+ const removeUndefinedProperties = (object: any) => {
150
+ return Object.fromEntries(Object.entries(object).filter(([_, v]) => v != null));
151
+ };
152
+
148
153
  Shadow.displayName = shadowName;
149
154
 
150
155
  export default Shadow;
@@ -1,6 +1,7 @@
1
- import type { ShadowToken } from '@fluentui-react-native/theme-types';
2
1
  import type { ViewProps } from 'react-native';
3
2
 
3
+ import type { ShadowToken } from '@fluentui-react-native/theme-types';
4
+
4
5
  export const shadowName = 'Shadow';
5
6
 
6
7
  export interface ShadowProps extends ViewProps {
@@ -1,10 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import { Text, View } from 'react-native';
3
- import { Shadow } from '../Shadow';
3
+
4
4
  import { mergeStyles, useFluentTheme } from '@fluentui-react-native/framework';
5
- import * as renderer from 'react-test-renderer';
6
- import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools';
7
5
  import { Pressable } from '@fluentui-react-native/pressable';
6
+ import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools';
7
+ import * as renderer from 'react-test-renderer';
8
+
9
+ import { Shadow } from '../Shadow';
8
10
 
9
11
  const backgroundColor = { backgroundColor: 'red' };
10
12
  interface ShadowTestProps {
@@ -23,12 +25,17 @@ const TestShadow: React.FunctionComponent<ShadowTestProps> = (props: ShadowTestP
23
25
  );
24
26
  };
25
27
 
26
- const TestPressableWithShadow: React.FunctionComponent = () => {
28
+ const TestPressableWithAndWithoutShadow: React.FunctionComponent = () => {
27
29
  const theme = useFluentTheme();
28
30
  return (
29
- <Shadow shadowToken={theme.shadows['shadow16']}>
30
- <Pressable style={backgroundColor} />
31
- </Shadow>
31
+ <View>
32
+ <Shadow shadowToken={theme.shadows['shadow16']}>
33
+ <Pressable style={backgroundColor} />
34
+ </Shadow>
35
+ <View>
36
+ <Pressable style={backgroundColor} />
37
+ </View>
38
+ </View>
32
39
  );
33
40
  };
34
41
 
@@ -115,8 +122,8 @@ describe('Shadow component tests', () => {
115
122
  expect(tree).toMatchSnapshot();
116
123
  });
117
124
 
118
- it('Pressable that has a shadow', () => {
119
- const tree = renderer.create(<TestPressableWithShadow />).toJSON();
125
+ it('Pressable that has a shadow vs. pressable without shadow', () => {
126
+ const tree = renderer.create(<TestPressableWithAndWithoutShadow />).toJSON();
120
127
  expect(tree).toMatchSnapshot();
121
128
  });
122
129