Skip to content

Commit d3bc7c4

Browse files
authored
fix(attach-step): Fix attach to function components (#49)
fix(attach-step): Fix attach to function components
1 parent 54db365 commit d3bc7c4

File tree

6 files changed

+217
-289
lines changed

6 files changed

+217
-289
lines changed

example/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@
10681068

10691069
"@stackbuilders/react-native-spotlight-tour@../stackbuilders-react-native-spotlight-tour-v0.0.0.tgz":
10701070
version "0.0.0"
1071-
resolved "../stackbuilders-react-native-spotlight-tour-v0.0.0.tgz#1c9cab35d8a64af870ea92fcd10a92078f3e6191"
1071+
resolved "../stackbuilders-react-native-spotlight-tour-v0.0.0.tgz#a50e50ba75ee637a0b40ea177f238640d79e6772"
10721072
dependencies:
10731073
react-native-responsive-dimensions "^3.1.1"
10741074
styled-components "^5.2.3"

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
"react-native": ">=0.50.0",
5353
"react-native-svg": ">=12.1.0"
5454
},
55+
"resolutions": {
56+
"@types/react-native": "^0.66.10"
57+
},
5558
"release": {
5659
"branches": [
5760
"release"

src/lib/AttachStep.component.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, { ClassAttributes, isValidElement, useContext, useEffect, useRef } from "react";
2-
import { StyleProp, View, ViewProps, ViewStyle } from "react-native";
1+
import React, { useContext, useEffect, useRef } from "react";
2+
import { StyleProp, View, ViewStyle } from "react-native";
3+
import styled from "styled-components/native";
34

45
import { SpotlightTourContext } from "./SpotlightTour.context";
56

@@ -9,6 +10,10 @@ interface AttachStepProps {
910
style?: StyleProp<ViewStyle>;
1011
}
1112

13+
const StepView = styled.View`
14+
align-self: flex-start;
15+
`;
16+
1217
export const AttachStep: React.FC<AttachStepProps> = ({ children, disabled, index, style }) => {
1318
const { current, changeSpot, spot } = useContext(SpotlightTourContext);
1419

@@ -26,16 +31,9 @@ export const AttachStep: React.FC<AttachStepProps> = ({ children, disabled, inde
2631
}
2732
}, [current, disabled]);
2833

29-
if (isValidElement(children) && React.Children.count(children) === 1) {
30-
return React.cloneElement<ClassAttributes<View> & ViewProps>(
31-
React.Children.only(children),
32-
{ ref: childRef, collapsable: false }
33-
);
34-
}
35-
3634
return (
37-
<View ref={childRef} collapsable={false} style={style}>
35+
<StepView ref={childRef} collapsable={false} style={style}>
3836
{children}
39-
</View>
37+
</StepView>
4038
);
4139
};

test/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe("Spotlight tour", () => {
177177
left: 325,
178178
marginBottom: "2%",
179179
position: "absolute",
180-
top: -72
180+
top: -79
181181
});
182182
});
183183
});

test/lib/tour-overlay/TourOverlay.component.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe("Lib.TourOverlay.TourOverlayComponent", () => {
6666
});
6767

6868
describe("and the next step is triggered", () => {
69-
it("rcalls the next callback once", async () => {
69+
it("calls the next callback once", async () => {
7070
const { getByText } = render(<TourOverlay tour={BASE_TOUR} />);
7171

7272
await waitFor(() => getByText("Step 1"));

0 commit comments

Comments
 (0)