Skip to content

Commit bcaf53c

Browse files
authored
fix(Guide): fixed component positioning errors in multiple scenarios (#3499)
1 parent 97bb580 commit bcaf53c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/guide/guide.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,16 @@ export default class Guide extends SuperComponent {
9090
const highlightPadding = rpx2px(step.highlightPadding ?? this.data.highlightPadding);
9191
const referenceTop = rect.top - highlightPadding;
9292
const referenceRight = systemInfo.windowWidth - rect.right - highlightPadding;
93-
const referenceBottom = systemInfo.windowHeight - rect.bottom - highlightPadding;
9493
const referenceLeft = rect.left - highlightPadding;
94+
const referenceWidth = rect.width + 2 * highlightPadding;
95+
const referenceHeight = rect.height + 2 * highlightPadding;
96+
9597
const style = {
9698
top: `${referenceTop}px`,
9799
right: `${referenceRight}px`,
98-
bottom: `${referenceBottom}px`,
99100
left: `${referenceLeft}px`,
101+
width: `${referenceWidth}px`,
102+
height: `${referenceHeight}px`,
100103
};
101104
this.setData({
102105
_steps: this.data.steps,
@@ -213,12 +216,11 @@ export default class Guide extends SuperComponent {
213216
const space = rpx2px(32);
214217
const offsetLeft = (offset) => unitConvert(isNumber(offset?.[0]) ? `${offset?.[0]}rpx` : offset?.[0] || 0);
215218
const offsetTop = (offset) => unitConvert(isNumber(offset?.[1]) ? `${offset?.[1]}rpx` : offset?.[1] || 0);
216-
const bottom = (place) => parseFloat(place.bottom);
217219
const left = (place) => parseFloat(place.left);
218220
const right = (place) => parseFloat(place.right);
219221
const top = (place) => parseFloat(place.top);
220-
const height = (place) => systemInfo.windowHeight - bottom(place) - top(place);
221-
const width = (place) => systemInfo.windowWidth - left(place) - right(place);
222+
const height = (place) => parseFloat(place.height);
223+
const width = (place) => parseFloat(place.width);
222224
return {
223225
center: (rect, place, offset) => ({
224226
top: `${Math.max(height(place) + top(place) + space + offsetTop(offset), 1)}px`,
@@ -245,7 +247,7 @@ export default class Guide extends SuperComponent {
245247
right: `${Math.max(width(place) + right(place) + space - offsetLeft(offset), 1)}px`,
246248
}),
247249
'left-bottom': (rect, place, offset) => ({
248-
bottom: `${Math.max(bottom(place) - offsetTop(offset), 1)}px`,
250+
top: `${Math.max(top(place) + height(place) - rect.height - offsetTop(offset), 1)}px`,
249251
right: `${Math.max(width(place) + right(place) + space - offsetLeft(offset), 1)}px`,
250252
}),
251253
right: (rect, place, offset) => ({
@@ -257,19 +259,19 @@ export default class Guide extends SuperComponent {
257259
left: `${Math.max(left(place) + width(place) + space + offsetLeft(offset), 1)}px`,
258260
}),
259261
'right-bottom': (rect, place, offset) => ({
260-
bottom: `${Math.max(bottom(place) - offsetTop(offset), 1)}px`,
262+
top: `${Math.max(top(place) + height(place) - rect.height - offsetTop(offset), 1)}px`,
261263
left: `${Math.max(left(place) + width(place) + space + offsetLeft(offset), 1)}px`,
262264
}),
263265
top: (rect, place, offset) => ({
264-
bottom: `${Math.max(height(place) + bottom(place) + space - offsetTop(offset), 1)}px`,
266+
top: `${Math.max(top(place) - rect.height - space + offsetTop(offset), 1)}px`,
265267
left: `${Math.max(width(place) / 2 + left(place) - rect.width / 2 + offsetLeft(offset), 1)}px`,
266268
}),
267269
'top-left': (rect, place, offset) => ({
268-
bottom: `${Math.max(height(place) + bottom(place) + space - offsetTop(offset), 1)}px`,
270+
top: `${Math.max(top(place) - rect.height - space + offsetTop(offset), 1)}px`,
269271
left: `${Math.max(left(place) + offsetLeft(offset), 1)}px`,
270272
}),
271273
'top-right': (rect, place, offset) => ({
272-
bottom: `${Math.max(height(place) + bottom(place) + space - offsetTop(offset), 1)}px`,
274+
top: `${Math.max(top(place) - rect.height - space + offsetTop(offset), 1)}px`,
273275
right: `${Math.max(right(place) - offsetLeft(offset), 1)}px`,
274276
}),
275277
};

0 commit comments

Comments
 (0)