|
1 | 1 | // @flow
|
2 | 2 | import React, { Component } from 'react';
|
3 |
| -import { Animated, Easing, View, NativeModules, Modal, StatusBar, Platform } from 'react-native'; |
| 3 | +import { |
| 4 | + Animated, |
| 5 | + Easing, |
| 6 | + View, |
| 7 | + NativeModules, |
| 8 | + Modal, |
| 9 | + StatusBar, |
| 10 | + Platform, |
| 11 | + I18nManager, |
| 12 | +} from 'react-native'; |
4 | 13 | import Tooltip from './Tooltip';
|
5 | 14 | import StepNumber from './StepNumber';
|
6 | 15 | import styles, { MARGIN, ARROW_SIZE, STEP_NUMBER_DIAMETER, STEP_NUMBER_RADIUS } from './style';
|
@@ -36,6 +45,10 @@ type State = {
|
36 | 45 |
|
37 | 46 | const noop = () => {};
|
38 | 47 |
|
| 48 | +const rtl = I18nManager.isRTL; |
| 49 | +const start = rtl ? 'right' : 'left'; |
| 50 | +const end = rtl ? 'left' : 'right'; |
| 51 | + |
39 | 52 | class CopilotModal extends Component<Props, State> {
|
40 | 53 | static defaultProps = {
|
41 | 54 | easing: Easing.elastic(0.7),
|
@@ -101,15 +114,31 @@ class CopilotModal extends Component<Props, State> {
|
101 | 114 | obj.top -= StatusBar.currentHeight; // eslint-disable-line no-param-reassign
|
102 | 115 | }
|
103 | 116 |
|
104 |
| - let stepNumberLeft = obj.left - STEP_NUMBER_RADIUS; |
| 117 | + let stepNumberLeft; |
| 118 | + |
| 119 | + const edgeCase = (stepLeft) => { |
| 120 | + if (stepLeft > layout.width - STEP_NUMBER_DIAMETER) { |
| 121 | + return layout.width - STEP_NUMBER_DIAMETER; |
| 122 | + } |
| 123 | + return stepLeft; |
| 124 | + }; |
| 125 | + |
| 126 | + if (!rtl) { |
| 127 | + stepNumberLeft = obj.left - STEP_NUMBER_RADIUS; |
105 | 128 |
|
106 |
| - if (stepNumberLeft < 0) { |
| 129 | + if (stepNumberLeft < 0) { |
| 130 | + stepNumberLeft = (obj.left + obj.width) - STEP_NUMBER_RADIUS; |
| 131 | + stepNumberLeft = edgeCase(stepNumberLeft); |
| 132 | + } |
| 133 | + } else { |
107 | 134 | stepNumberLeft = (obj.left + obj.width) - STEP_NUMBER_RADIUS;
|
108 |
| - if (stepNumberLeft > layout.width - STEP_NUMBER_DIAMETER) { |
109 |
| - stepNumberLeft = layout.width - STEP_NUMBER_DIAMETER; |
| 135 | + if (stepNumberLeft > layout.width) { |
| 136 | + stepNumberLeft = obj.left - STEP_NUMBER_RADIUS; |
| 137 | + stepNumberLeft = edgeCase(stepNumberLeft); |
110 | 138 | }
|
111 | 139 | }
|
112 | 140 |
|
| 141 | + |
113 | 142 | const center = {
|
114 | 143 | x: obj.left + (obj.width / 2),
|
115 | 144 | y: obj.top + (obj.height / 2),
|
@@ -137,15 +166,15 @@ class CopilotModal extends Component<Props, State> {
|
137 | 166 | }
|
138 | 167 |
|
139 | 168 | if (horizontalPosition === 'left') {
|
140 |
| - tooltip.right = Math.max(layout.width - (obj.left + obj.width), 0); |
| 169 | + tooltip[end] = Math.max(layout.width - (obj.left + obj.width), 0); |
141 | 170 | tooltip.right = tooltip.right === 0 ? tooltip.right + MARGIN : tooltip.right;
|
142 | 171 | tooltip.maxWidth = layout.width - tooltip.right - MARGIN;
|
143 |
| - arrow.right = tooltip.right + MARGIN; |
| 172 | + arrow[end] = tooltip[end] + MARGIN; |
144 | 173 | } else {
|
145 |
| - tooltip.left = Math.max(obj.left, 0); |
| 174 | + tooltip[start] = Math.max(obj.left, 0); |
146 | 175 | tooltip.left = tooltip.left === 0 ? tooltip.left + MARGIN : tooltip.left;
|
147 | 176 | tooltip.maxWidth = layout.width - tooltip.left - MARGIN;
|
148 |
| - arrow.left = tooltip.left + MARGIN; |
| 177 | + arrow[start] = tooltip[start] + MARGIN; |
149 | 178 | }
|
150 | 179 |
|
151 | 180 | const animate = {
|
@@ -249,7 +278,7 @@ class CopilotModal extends Component<Props, State> {
|
249 | 278 | style={[
|
250 | 279 | styles.stepNumberContainer,
|
251 | 280 | {
|
252 |
| - left: this.state.animatedValues.stepNumberLeft, |
| 281 | + [start]: this.state.animatedValues.stepNumberLeft, |
253 | 282 | top: Animated.add(this.state.animatedValues.top, -STEP_NUMBER_RADIUS),
|
254 | 283 | },
|
255 | 284 | ]}
|
|
0 commit comments