Skip to content

Commit

Permalink
doc: Add tips for reduce motion enabled. (#698)
Browse files Browse the repository at this point in the history
* doc: Add tips for reduce motion enabled.

* doc: Add tips for reduce motion enabled.
  • Loading branch information
dohooo authored Oct 5, 2024
1 parent 3d156a9 commit ff3b32e
Show file tree
Hide file tree
Showing 47 changed files with 370 additions and 137 deletions.
5 changes: 5 additions & 0 deletions example/app/app/+html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ export default function Root({ children }: { children: React.ReactNode }) {
}
const carouselComponent = document.getElementById("carousel-component");
if (carouselComponent) {
const kind = carouselComponent.getAttribute("data-kind");
const name = carouselComponent.getAttribute("data-name");
window.parent.postMessage(
{
type: "carouselHeight",
height: carouselComponent.offsetHeight,
kind,
name,
},
"*",
);
Expand Down
43 changes: 43 additions & 0 deletions example/app/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { routes } from "./routes";
import { useInDoc } from "@/hooks/useInDoc";
import { IS_WEB } from "@/constants/platform";
import { MAX_WIDTH } from "@/constants/sizes";
import { Link } from "expo-router";
import { useReducedMotion } from "react-native-reanimated";

export {
// Catch any errors thrown by the Layout component.
Expand Down Expand Up @@ -61,6 +63,23 @@ function RootLayoutNav() {
? tamaguiConfig.themes.dark.background.val
: tamaguiConfig.themes.light.background.val;

const reduceMotion = useReducedMotion();

// post message to parent doc
useEffect(() => {
if (!inDoc) {
return;
}

window.parent.postMessage(
{
type: "reduceMotion",
reduceMotion,
},
"*",
);
}, [reduceMotion]);

return (
<TamaguiProvider
config={tamaguiConfig}
Expand All @@ -73,6 +92,30 @@ function RootLayoutNav() {
backgroundColor={backgroundColor}
>
<YStack minWidth={IS_WEB ? MAX_WIDTH : "100%"} height={"100%"}>
{IS_WEB && !inDoc && reduceMotion && (
<XStack paddingHorizontal={"$2"} width={MAX_WIDTH}>
<Text
style={{
color: "red",
textAlign: "center",
opacity: 0.75,
fontSize: 12,
}}
>
It looks like reduced motion is turned on in your system
preferences. Some of the animations may be skipped.{" "}
<Link
target="_blank"
style={{ textDecorationLine: "underline" }}
href={
"https://docs.swmansion.com/react-native-reanimated/docs/guides/accessibility/#reduced-motion-in-animations"
}
>
Learn more
</Link>
</Text>
</XStack>
)}
<Stack
initialRouteName="/"
screenOptions={{
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/basic-layouts/left-align/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const defaultDataWith6Colors = [

function Index() {
return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "basic-layouts", name: "left-align" }}
>
<Carousel
loop={true}
width={430}
Expand Down
7 changes: 5 additions & 2 deletions example/app/app/demos/basic-layouts/normal/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ function Index() {
const scrollOffsetValue = useSharedValue<number>(0);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "basic-layouts", name: "normal" }}
>
<Carousel
testID={"xxx"}
loop={true}
Expand All @@ -40,7 +43,7 @@ function Index() {
g.enabled(false);
}}
onSnapToItem={(index: number) => console.log("current index:", index)}
renderItem={renderItem()}
renderItem={renderItem({ rounded: true })}
/>
</View>
);
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/basic-layouts/parallax/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ function Index() {
const progress = useSharedValue<number>(0);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "basic-layouts", name: "parallax" }}
>
<Carousel
autoPlayInterval={2000}
data={defaultDataWith6Colors}
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/basic-layouts/stack/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ function Index() {
const ref = React.useRef<ICarouselInstance>(null);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "basic-layouts", name: "stack" }}
>
<Carousel
ref={ref}
autoPlayInterval={2000}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ function Index() {
}, []);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "advanced-parallax" }}
>
<CaptureWrapper>
<Carousel
loop={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ function Index() {
});

return (
<View style={{ paddingVertical: 100 }} id="carousel-component">
<View
style={{ paddingVertical: 100 }}
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "anim-tab-bar" }}
>
<Carousel
ref={r}
loop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const PAGE_WIDTH = window.width / 2;

function Index() {
return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "blur-parallax" }}
>
<Carousel
loop={true}
style={{
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/custom-animations/blur-rotate/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ function Index() {
const ITEM_WIDTH = PAGE_WIDTH * 0.8;

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "blur-rotate" }}
>
<Carousel
vertical
loop={false}
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/custom-animations/circular/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ function Index() {
);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "circular" }}
>
<Carousel
width={itemSize}
height={itemSize}
Expand Down
1 change: 1 addition & 0 deletions example/app/app/demos/custom-animations/cube-3d/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Index() {
<View
style={{ display: "flex", flexDirection: "row", flexWrap: "wrap" }}
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "cube-3d" }}
>
{Array.from({
length: count * 3,
Expand Down
1 change: 1 addition & 0 deletions example/app/app/demos/custom-animations/curve/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function Index() {
alignItems: "center",
}}
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "curve" }}
>
<Carousel
{...baseOptions}
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/custom-animations/flow/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ function Index() {
);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "flow" }}
>
<Carousel
loop
vertical
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/custom-animations/fold/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ function Index() {
);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "fold" }}
>
<Carousel
width={itemSize}
height={PAGE_WIDTH / 2}
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/custom-animations/multiple/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const COUNT = 6;

function Index() {
return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "multiple" }}
>
<Carousel
loop
autoPlay
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/custom-animations/press-swipe/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ function Index() {
}, []);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "press-swipe" }}
>
<Carousel
loop={true}
style={{ width: PAGE_WIDTH, height: 240 }}
Expand Down
6 changes: 5 additions & 1 deletion example/app/app/demos/custom-animations/quick-swipe/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ function Index() {
} as const;

return (
<View id="carousel-component" style={{ paddingVertical: 20 }}>
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "quick-swipe" }}
style={{ paddingVertical: 20 }}
>
<Carousel
{...baseOptions}
loop={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ function Index() {
}, []);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "rotate-fade-in-out" }}
>
<Carousel
loop
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function Index() {
}, []);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "rotate-in-out" }}
>
<Carousel
loop
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ function Index() {
}, []);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "scale-fade-in-out" }}
>
<Carousel
loop
style={{
Expand Down
5 changes: 4 additions & 1 deletion example/app/app/demos/custom-animations/tinder/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ function Index() {
);

return (
<View id="carousel-component">
<View
id="carousel-component"
dataSet={{ kind: "custom-animations", name: "tinder" }}
>
<Carousel
loop={false}
style={{
Expand Down
6 changes: 5 additions & 1 deletion example/app/app/demos/utils/pagination/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ function Index() {
};

return (
<View id="carousel-component" style={{ gap: 10 }}>
<View
id="carousel-component"
dataSet={{ kind: "utils", name: "pagination" }}
style={{ gap: 10 }}
>
<View style={{ marginBottom: 10 }}>
<Carousel
ref={ref}
Expand Down
9 changes: 9 additions & 0 deletions example/app/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "react-native";

declare module "react-native" {
interface ViewProps {
dataSet?: {
[key: string]: string;
};
}
}
Loading

0 comments on commit ff3b32e

Please sign in to comment.