Skip to content

Commit dd12b94

Browse files
ethansharInbal-Tish
authored andcommitted
support passing screen width for the hint container (#510)
* support passing screen width for the hint container * rename screenWidth to containerWidth
1 parent 36a5bbd commit dd12b94

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/components/hint/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ class Hint extends BaseComponent {
106106
* Callback for the background press
107107
*/
108108
onBackgroundPress: PropTypes.func,
109+
/**
110+
* The hint container width
111+
*/
112+
containerWidth: PropTypes.number,
109113
/**
110114
* The hint's test identifier
111115
*/
@@ -141,6 +145,11 @@ class Hint extends BaseComponent {
141145
}
142146
};
143147

148+
get containerWidth() {
149+
const {containerWidth} = this.getThemeProps();
150+
return containerWidth || Constants.screenWidth;
151+
}
152+
144153
get targetLayout() {
145154
const {onBackgroundPress, targetFrame} = this.props;
146155
const {targetLayout, targetLayoutInWindow} = this.state;
@@ -181,9 +190,9 @@ class Hint extends BaseComponent {
181190
getTargetPositionOnScreen() {
182191
const targetMidPosition = this.targetLayout.x + this.targetLayout.width / 2;
183192

184-
if (targetMidPosition > Constants.screenWidth * (2 / 3)) {
193+
if (targetMidPosition > this.containerWidth * (2 / 3)) {
185194
return TARGET_POSITIONS.RIGHT;
186-
} else if (targetMidPosition < Constants.screenWidth * (1 / 3)) {
195+
} else if (targetMidPosition < this.containerWidth * (1 / 3)) {
187196
return TARGET_POSITIONS.LEFT;
188197
}
189198
return TARGET_POSITIONS.CENTER;
@@ -222,7 +231,7 @@ class Hint extends BaseComponent {
222231
if (targetPositionOnScreen === TARGET_POSITIONS.LEFT) {
223232
paddings.paddingLeft = this.targetLayout.x;
224233
} else if (targetPositionOnScreen === TARGET_POSITIONS.RIGHT) {
225-
paddings.paddingRight = Constants.screenWidth - this.targetLayout.x - this.targetLayout.width;
234+
paddings.paddingRight = this.containerWidth - this.targetLayout.x - this.targetLayout.width;
226235
}
227236
}
228237
return paddings;
@@ -243,8 +252,8 @@ class Hint extends BaseComponent {
243252

244253
const leftPosition = this.useSideTip ? this.targetLayout.x : this.targetLayout.x + targetMidWidth - tipMidWidth;
245254
const rightPosition = this.useSideTip
246-
? Constants.screenWidth - this.targetLayout.x - this.targetLayout.width
247-
: Constants.screenWidth - this.targetLayout.x - targetMidWidth - tipMidWidth;
255+
? this.containerWidth - this.targetLayout.x - this.targetLayout.width
256+
: this.containerWidth - this.targetLayout.x - targetMidWidth - tipMidWidth;
248257
const targetPositionOnScreen = this.getTargetPositionOnScreen();
249258

250259
switch (targetPositionOnScreen) {
@@ -315,7 +324,7 @@ class Hint extends BaseComponent {
315324
<AnimatableView
316325
animation={shownUp ? AnimatableManager.animations.hintAppearUp : AnimatableManager.animations.hintAppearDown}
317326
duration={200}
318-
style={[{width: Constants.screenWidth}, styles.animatedContainer, this.getHintPosition(), this.getHintPadding()]}
327+
style={[{width: this.containerWidth}, styles.animatedContainer, this.getHintPosition(), this.getHintPadding()]}
319328
pointerEvents="box-none"
320329
testID={testID}
321330
>

0 commit comments

Comments
 (0)