Skip to content

Commit

Permalink
fix(attach-step): Fix attach to function components (#49)
Browse files Browse the repository at this point in the history
fix(attach-step): Fix attach to function components
  • Loading branch information
JoseLion authored Jan 7, 2022
1 parent 54db365 commit d3bc7c4
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 289 deletions.
2 changes: 1 addition & 1 deletion example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@

"@stackbuilders/react-native-spotlight-tour@../stackbuilders-react-native-spotlight-tour-v0.0.0.tgz":
version "0.0.0"
resolved "../stackbuilders-react-native-spotlight-tour-v0.0.0.tgz#1c9cab35d8a64af870ea92fcd10a92078f3e6191"
resolved "../stackbuilders-react-native-spotlight-tour-v0.0.0.tgz#a50e50ba75ee637a0b40ea177f238640d79e6772"
dependencies:
react-native-responsive-dimensions "^3.1.1"
styled-components "^5.2.3"
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"react-native": ">=0.50.0",
"react-native-svg": ">=12.1.0"
},
"resolutions": {
"@types/react-native": "^0.66.10"
},
"release": {
"branches": [
"release"
Expand Down
20 changes: 9 additions & 11 deletions src/lib/AttachStep.component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ClassAttributes, isValidElement, useContext, useEffect, useRef } from "react";
import { StyleProp, View, ViewProps, ViewStyle } from "react-native";
import React, { useContext, useEffect, useRef } from "react";
import { StyleProp, View, ViewStyle } from "react-native";
import styled from "styled-components/native";

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

Expand All @@ -9,6 +10,10 @@ interface AttachStepProps {
style?: StyleProp<ViewStyle>;
}

const StepView = styled.View`
align-self: flex-start;
`;

export const AttachStep: React.FC<AttachStepProps> = ({ children, disabled, index, style }) => {
const { current, changeSpot, spot } = useContext(SpotlightTourContext);

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

if (isValidElement(children) && React.Children.count(children) === 1) {
return React.cloneElement<ClassAttributes<View> & ViewProps>(
React.Children.only(children),
{ ref: childRef, collapsable: false }
);
}

return (
<View ref={childRef} collapsable={false} style={style}>
<StepView ref={childRef} collapsable={false} style={style}>
{children}
</View>
</StepView>
);
};
2 changes: 1 addition & 1 deletion test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe("Spotlight tour", () => {
left: 325,
marginBottom: "2%",
position: "absolute",
top: -72
top: -79
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/lib/tour-overlay/TourOverlay.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("Lib.TourOverlay.TourOverlayComponent", () => {
});

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

await waitFor(() => getByText("Step 1"));
Expand Down
Loading

0 comments on commit d3bc7c4

Please sign in to comment.