react-native-ui-lib 8.0.1-snapshot.7558 → 8.0.1-snapshot.7561

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ui-lib",
3
- "version": "8.0.1-snapshot.7558",
3
+ "version": "8.0.1-snapshot.7561",
4
4
  "main": "src/index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "author": "Ethan Sharabi <ethan.shar@gmail.com>",
@@ -32,14 +32,15 @@ describe('FloatingButton', () => {
32
32
  testID: `${TEST_ID}.button`
33
33
  });
34
34
  expect(await buttonDriver.exists()).not.toBeTruthy();
35
- renderTree.rerender(<TestCase visible />);
35
+ renderTree.rerender(<TestCase visible button={button} />);
36
36
  expect(await buttonDriver.exists()).toBeTruthy();
37
37
  });
38
38
  });
39
39
  describe('buttons', () => {
40
40
  it('should render a button', async () => {
41
41
  const props = {
42
- visible: true
42
+ visible: true,
43
+ button
43
44
  };
44
45
  const renderTree = render(<TestCase {...props} />);
45
46
  const buttonDriver = ButtonDriver({
@@ -87,7 +88,8 @@ describe('FloatingButton', () => {
87
88
  describe('bottomMargin', () => {
88
89
  it('should have default bottom margin', () => {
89
90
  const props = {
90
- visible: true
91
+ visible: true,
92
+ button
91
93
  };
92
94
  const renderTree = render(<TestCase {...props} />);
93
95
  const buttonDriver = ButtonDriver({
@@ -99,6 +101,7 @@ describe('FloatingButton', () => {
99
101
  it('should have default bottom margin for both buttons', () => {
100
102
  const props = {
101
103
  visible: true,
104
+ button,
102
105
  secondaryButton
103
106
  };
104
107
  const renderTree = render(<TestCase {...props} />);
@@ -116,6 +119,7 @@ describe('FloatingButton', () => {
116
119
  it('should have bottom margin that match bottomMargin prop', () => {
117
120
  const props = {
118
121
  visible: true,
122
+ button,
119
123
  bottomMargin: 10
120
124
  };
121
125
  const renderTree = render(<TestCase {...props} />);
@@ -128,6 +132,7 @@ describe('FloatingButton', () => {
128
132
  it('should have bottom margin for secondary button that match bottomMarginProp', () => {
129
133
  const props = {
130
134
  visible: true,
135
+ button,
131
136
  secondaryButton,
132
137
  bottomMargin: 10
133
138
  };
@@ -148,6 +153,7 @@ describe('FloatingButton', () => {
148
153
  it('should style vertical layout (default)', () => {
149
154
  const props = {
150
155
  visible: true,
156
+ button,
151
157
  secondaryButton
152
158
  };
153
159
  const renderTree = render(<TestCase {...props} />);
@@ -163,6 +169,7 @@ describe('FloatingButton', () => {
163
169
  it('should style horizontal layout', () => {
164
170
  const props = {
165
171
  visible: true,
172
+ button,
166
173
  secondaryButton,
167
174
  buttonLayout: FloatingButtonLayouts.HORIZONTAL
168
175
  };
@@ -181,6 +188,7 @@ describe('FloatingButton', () => {
181
188
  it('should style vertical layout (default) when fullWidth is true', () => {
182
189
  const props = {
183
190
  visible: true,
191
+ button,
184
192
  secondaryButton,
185
193
  fullWidth: true
186
194
  };
@@ -202,6 +210,7 @@ describe('FloatingButton', () => {
202
210
  it('should style horizontal layout when fullWidth is true', () => {
203
211
  const props = {
204
212
  visible: true,
213
+ button,
205
214
  secondaryButton,
206
215
  buttonLayout: FloatingButtonLayouts.HORIZONTAL,
207
216
  fullWidth: true
@@ -55,19 +55,30 @@ class FloatingButton extends PureComponent {
55
55
  }]
56
56
  };
57
57
  };
58
- get isSecondaryHorizontal() {
58
+ get isSecondaryOnly() {
59
59
  const {
60
60
  secondaryButton,
61
+ button
62
+ } = this.props;
63
+ return !!secondaryButton && !button;
64
+ }
65
+ get isHorizontalLayout() {
66
+ const {
61
67
  buttonLayout
62
68
  } = this.props;
63
- return secondaryButton && buttonLayout === FloatingButtonLayouts.HORIZONTAL;
69
+ return buttonLayout === FloatingButtonLayouts.HORIZONTAL || this.isSecondaryOnly;
70
+ }
71
+ get isSecondaryHorizontal() {
72
+ const {
73
+ secondaryButton
74
+ } = this.props;
75
+ return secondaryButton && this.isHorizontalLayout;
64
76
  }
65
77
  get isSecondaryVertical() {
66
78
  const {
67
- secondaryButton,
68
- buttonLayout
79
+ secondaryButton
69
80
  } = this.props;
70
- return secondaryButton && buttonLayout === FloatingButtonLayouts.VERTICAL;
81
+ return secondaryButton && !this.isHorizontalLayout;
71
82
  }
72
83
  renderButton() {
73
84
  const {
@@ -76,17 +87,17 @@ class FloatingButton extends PureComponent {
76
87
  fullWidth,
77
88
  testID
78
89
  } = this.props;
79
- const bottom = this.isSecondaryVertical ? Spacings.s4 : bottomMargin || Spacings.s8;
80
- const left = this.isSecondaryHorizontal || fullWidth ? Spacings.s4 : undefined;
81
- const right = this.isSecondaryHorizontal ? 20 : fullWidth ? Spacings.s4 : undefined;
82
- const shadowStyle = !button?.outline && !button?.link && styles.shadow;
83
- const marginStyle = {
84
- marginTop: 16,
85
- marginBottom: bottom,
86
- marginLeft: left,
87
- marginRight: right
88
- };
89
- return <Button size={Button.sizes.large} flex={!!this.isSecondaryHorizontal} style={[shadowStyle, marginStyle]} testID={`${testID}.button`} {...button} />;
90
+ if (button) {
91
+ const shadowStyle = button && !button.outline && !button.link ? styles.shadow : undefined;
92
+ const marginStyle = {
93
+ marginTop: Spacings.s4,
94
+ marginBottom: this.isSecondaryVertical ? Spacings.s4 : bottomMargin || Spacings.s8,
95
+ marginLeft: this.isSecondaryHorizontal || fullWidth ? Spacings.s4 : undefined,
96
+ marginRight: this.isSecondaryHorizontal ? Spacings.s5 : fullWidth ? Spacings.s4 : undefined
97
+ };
98
+ const shouldFlex = this.isSecondaryHorizontal || fullWidth && this.isHorizontalLayout;
99
+ return <Button size={Button.sizes.large} flex={!!shouldFlex} style={[shadowStyle, marginStyle]} testID={`${testID}.button`} {...button} />;
100
+ }
90
101
  }
91
102
  renderOverlay = () => {
92
103
  if (!this.props.hideBackgroundOverlay) {
@@ -100,25 +111,44 @@ class FloatingButton extends PureComponent {
100
111
  secondaryButton,
101
112
  bottomMargin,
102
113
  testID,
103
- buttonLayout
114
+ fullWidth,
115
+ button
104
116
  } = this.props;
105
- const bgColor = secondaryButton?.backgroundColor || Colors.$backgroundDefault;
106
- const isHorizontal = buttonLayout === FloatingButtonLayouts.HORIZONTAL;
107
- const buttonStyle = isHorizontal ? [styles.shadow, styles.secondaryMargin, {
108
- backgroundColor: bgColor
109
- }] : {
110
- marginBottom: bottomMargin || Spacings.s7
111
- };
112
- return <Button outline={isHorizontal} flex={isHorizontal} link={!isHorizontal} size={Button.sizes.large} testID={`${testID}.secondaryButton`} {...secondaryButton} style={buttonStyle} enableShadow={false} />;
117
+ if (secondaryButton) {
118
+ const bgColor = secondaryButton.backgroundColor || Colors.$backgroundDefault;
119
+ const shouldFlex = this.isHorizontalLayout && !!button || fullWidth && this.isSecondaryOnly;
120
+ const buttonStyle = this.isHorizontalLayout ? [styles.shadow, styles.horizontalSecondaryMargin, {
121
+ backgroundColor: bgColor
122
+ }] : {
123
+ marginBottom: bottomMargin || Spacings.s7
124
+ };
125
+ return <Button outline={this.isHorizontalLayout} flex={shouldFlex} link={!this.isHorizontalLayout} size={Button.sizes.large} testID={`${testID}.secondaryButton`} {...secondaryButton} style={buttonStyle} enableShadow={false} />;
126
+ }
127
+ }
128
+ renderHorizontalLayout() {
129
+ return <>
130
+ {this.renderOverlay()}
131
+ {this.renderSecondaryButton()}
132
+ {this.renderButton()}
133
+ </>;
134
+ }
135
+ renderVerticalLayout() {
136
+ return <>
137
+ {this.renderOverlay()}
138
+ {this.renderButton()}
139
+ {this.renderSecondaryButton()}
140
+ </>;
113
141
  }
114
142
  render() {
143
+ // NOTE: keep this.firstLoad as true as long as the visibility changed to true
115
144
  const {
116
145
  withoutAnimation,
117
146
  visible,
118
147
  fullWidth,
119
- testID
148
+ testID,
149
+ button,
150
+ secondaryButton
120
151
  } = this.props;
121
- // NOTE: keep this.firstLoad as true as long as the visibility changed to true
122
152
  this.firstLoad && !visible ? this.firstLoad = true : this.firstLoad = false;
123
153
 
124
154
  // NOTE: On first load, don't show if it should not be visible
@@ -128,12 +158,13 @@ class FloatingButton extends PureComponent {
128
158
  if (!visible && withoutAnimation) {
129
159
  return false;
130
160
  }
131
- return <View row={this.isSecondaryHorizontal} center={this.isSecondaryHorizontal || !fullWidth} pointerEvents="box-none" animated style={[styles.container, this.getAnimatedStyle()]} testID={testID}>
132
- {this.renderOverlay()}
133
- {this.isSecondaryHorizontal && this.renderSecondaryButton()}
134
- {this.renderButton()}
135
- {this.isSecondaryVertical && this.renderSecondaryButton()}
136
- </View>;
161
+ if (button || secondaryButton) {
162
+ const hasBothButtons = !!(button && secondaryButton);
163
+ const shouldCenter = !fullWidth || this.isHorizontalLayout && hasBothButtons;
164
+ return <View row={this.isHorizontalLayout} center={shouldCenter} pointerEvents="box-none" animated style={[styles.container, this.getAnimatedStyle()]} testID={testID}>
165
+ {this.isHorizontalLayout ? this.renderHorizontalLayout() : this.renderVerticalLayout()}
166
+ </View>;
167
+ }
137
168
  }
138
169
  }
139
170
  const styles = StyleSheet.create({
@@ -149,10 +180,10 @@ const styles = StyleSheet.create({
149
180
  shadow: {
150
181
  ...Shadows.sh20.bottom
151
182
  },
152
- secondaryMargin: {
183
+ horizontalSecondaryMargin: {
153
184
  marginTop: Spacings.s4,
154
185
  marginBottom: Spacings.s7,
155
- marginLeft: 20
186
+ marginLeft: Spacings.s5
156
187
  }
157
188
  });
158
189
  export default asBaseComponent(FloatingButton);