@rpg-engine/long-bow 0.5.71 → 0.5.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.5.71",
3
+ "version": "0.5.73",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -82,6 +82,7 @@
82
82
  "uuid": "^8.3.2"
83
83
  },
84
84
  "dependencies": {
85
+ "@capacitor/core": "^4.6.3",
85
86
  "@rollup/plugin-image": "^2.1.1",
86
87
  "@rpg-engine/shared": "^0.9.19",
87
88
  "dayjs": "^1.11.2",
@@ -1,58 +1,74 @@
1
+ import { Capacitor } from '@capacitor/core';
1
2
  import React, { useEffect, useRef, useState } from 'react';
2
3
  import styled, { keyframes } from 'styled-components';
3
4
  import SelectArrow from '../Arrow/SelectArrow';
4
5
 
5
6
  export interface ISimpleImageCarousel {
6
- images: string[];
7
+ basePath: string;
8
+ imagesSrc: string[];
7
9
  styles?: React.CSSProperties;
8
10
  autoCycle?: boolean;
9
11
  autoCycleDelay?: number;
10
12
  stopAutoCyclingOnInteraction?: boolean;
11
13
  }
12
14
 
13
- export const SimpleImageCarousel: React.FC<ISimpleImageCarousel> = ({
14
- images,
15
+ const getTransformedBasePath = (basePath: string): string => {
16
+ if (Capacitor.isNativePlatform()) {
17
+ return Capacitor.convertFileSrc(basePath);
18
+ }
19
+ return basePath;
20
+ };
21
+
22
+ export const SimpleImageCarousel = ({
23
+ basePath,
24
+ imagesSrc,
15
25
  styles,
16
26
  autoCycle = false,
17
27
  autoCycleDelay = 3000,
18
28
  stopAutoCyclingOnInteraction = false,
19
- }) => {
29
+ }: ISimpleImageCarousel) => {
20
30
  const [currentImage, setCurrentImage] = useState(0);
21
- const autoCycleId = useRef<NodeJS.Timeout | null>(null);
31
+ const isInteracted = useRef<boolean>(false);
22
32
 
23
- const handleLeftClick = () => {
24
- setCurrentImage(
25
- prevImage => (prevImage - 1 + images?.length) % images?.length
26
- );
27
- if (stopAutoCyclingOnInteraction && autoCycleId.current) {
28
- clearInterval(autoCycleId.current);
29
- autoCycleId.current = null;
30
- }
31
- };
33
+ useEffect(() => {
34
+ let timer: NodeJS.Timeout | null = null;
32
35
 
33
- const handleRightClick = () => {
34
- setCurrentImage(prevImage => (prevImage + 1) % images?.length);
35
- if (stopAutoCyclingOnInteraction && autoCycleId.current) {
36
- clearInterval(autoCycleId.current);
37
- autoCycleId.current = null;
38
- }
39
- };
36
+ if (autoCycle && !isInteracted.current) {
37
+ timer = setInterval(() => {
38
+ if (stopAutoCyclingOnInteraction && isInteracted.current) {
39
+ clearInterval(timer!);
40
+ return;
41
+ }
40
42
 
41
- useEffect(() => {
42
- if (autoCycle) {
43
- autoCycleId.current = setInterval(() => {
44
- setCurrentImage(prevImage => (prevImage + 1) % images?.length);
43
+ handleRightClick(true);
45
44
  }, autoCycleDelay);
46
45
  }
47
46
 
48
47
  return () => {
49
- if (autoCycleId.current) {
50
- clearInterval(autoCycleId.current);
48
+ if (timer) {
49
+ clearInterval(timer);
51
50
  }
52
51
  };
53
- }, [autoCycle, autoCycleDelay, images?.length]);
52
+ }, [autoCycle, autoCycleDelay]);
53
+
54
+ const handleLeftClick = () => {
55
+ isInteracted.current = true;
56
+ setCurrentImage(oldImage =>
57
+ oldImage === 0 ? imagesSrc.length - 1 : oldImage - 1
58
+ );
59
+ };
60
+
61
+ const handleRightClick = (isAutomatedClick: boolean = false) => {
62
+ if (!isAutomatedClick) {
63
+ isInteracted.current = true;
64
+ }
65
+
66
+ setCurrentImage(oldImage =>
67
+ oldImage === imagesSrc.length - 1 ? 0 : oldImage + 1
68
+ );
69
+ };
54
70
 
55
- const hasMoreThanOneImage = images?.length > 1;
71
+ const hasMoreThanOneImage = imagesSrc.length > 1;
56
72
 
57
73
  return (
58
74
  <ImageContainer style={styles}>
@@ -65,8 +81,8 @@ export const SimpleImageCarousel: React.FC<ISimpleImageCarousel> = ({
65
81
  <Carousel>
66
82
  <FadeInCarouselImg
67
83
  key={currentImage}
68
- src={images?.[currentImage]}
69
- alt={`Image ${currentImage}`}
84
+ src={`${getTransformedBasePath(basePath)}/${imagesSrc[currentImage]}`}
85
+ alt={imagesSrc[currentImage]}
70
86
  />
71
87
  </Carousel>
72
88
  </ImageContainer>
@@ -82,7 +98,6 @@ const ImageContainer = styled.div`
82
98
  margin-right: 0.5rem;
83
99
  max-width: 400px;
84
100
  position: relative;
85
- width: 400px;
86
101
  `;
87
102
 
88
103
  const CustomLeftArrow = styled(SelectArrow)`
@@ -7,8 +7,6 @@ import {
7
7
  } from '../components/ImageCarousel/SimpleImageCarousel';
8
8
 
9
9
  import styled from 'styled-components';
10
- import image1 from '../assets/images/backpack.png';
11
- import image2 from '../assets/images/depot.png';
12
10
  import { RPGUIRoot } from '../components/RPGUI/RPGUIRoot';
13
11
 
14
12
  const meta: Meta = {
@@ -39,7 +37,8 @@ const CenteredContainer = styled.div`
39
37
  export const SimpleImageCarouselStory = Template.bind({});
40
38
 
41
39
  SimpleImageCarouselStory.args = {
42
- images: [image1, image2],
40
+ imagesSrc: ['./images/backpack.png', './images/depot.png'],
41
+ basePath: 'http://localhost:6006',
43
42
  autoCycle: true,
44
43
  stopAutoCyclingOnInteraction: true,
45
44
  };
Binary file
Binary file