Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8d384539

Přidáno uživatelem Fantič před více než 1 rok

re #10871: PlanViewPage: CastlePlanView: zoom in, out

Zobrazit rozdíly:

package.json
26 26
    "react-native-deck-swiper": "^1.1.7",
27 27
    "react-native-gesture-handler": "~2.12.0",
28 28
    "react-native-logs": "^5.0.1",
29
    "react-native-maps": "^1.8.0",
30 29
    "react-native-multiple-select": "^0.5.12",
31 30
    "react-native-reanimated": "~3.3.0",
32 31
    "react-native-safe-area-context": "4.6.3",
......
45 44
    "@tsconfig/react-native": "^2.0.3",
46 45
    "@types/jest": "^29.5.0",
47 46
    "@types/react": "~18.2.14",
48
    "@types/react-native-maps": "^0.24.2",
49 47
    "@types/react-test-renderer": "^18.0.0",
50 48
    "typescript": "^5.1.3"
51 49
  },
src/components/plan/CastlePlanView.tsx
1
import { VStack, Box, Text, HStack, ScrollView, Flex, Button, CloseIcon, IconButton, TextArea, useToast } from "native-base";
2
import { Note } from "../../types/note";
3
import React, { useCallback, useState } from "react";
4
import { Floor, PlanImage, Room } from "../../types/plan";
5

  
6
import MapView, { Marker } from 'react-native-maps';
7
import Svg, { Image, SvgXml } from 'react-native-svg';
8
import SvgImage from "react-native-svg/lib/typescript/elements/Image";
1
import { Box } from 'native-base';
2
import React, { useRef } from 'react';
3
import { StyleSheet, Dimensions } from 'react-native';
4
import { PinchGestureHandler } from 'react-native-gesture-handler';
5
import Animated, {
6
    useAnimatedGestureHandler,
7
    useAnimatedStyle,
8
    useSharedValue,
9
} from 'react-native-reanimated';
10
import { PlanImage } from '../../types/plan';
11
import { Room } from '../../types/searchFormTypes';
12
import Svg, { SvgXml } from 'react-native-svg';
9 13

  
10 14
const CastlePlanView = (props: { mapImage: PlanImage, selectedRoom?: Room }) => {
15
    const { mapImage } = props;
16

  
17
    const svgRef = useRef<React.ReactElement>();
18

  
19
    const translateX = useSharedValue(0);
20
    const translateY = useSharedValue(0);
21
    const scale = useSharedValue(1);
22

  
23
    console.log(mapImage.svg.substring(0,500))
24

  
25
    const DEFAULT_SCALE = 0
26
    const MIN_SCALE = 0.95
11 27

  
12
    const { mapImage, selectedRoom } = props
28
    const onGestureEvent = useAnimatedGestureHandler({
29
        onActive: (event: any) => {
30
            
31
            // handle one finger -> drag
32
            if (event.numberOfPointers === 1) {
33
            
34
            }
35
            // handle two fingers -> zoom  + - 
36
            else if (event.numberOfPointers === 2) {
13 37

  
14
    console.log(mapImage.svg.substring(0, 500))
38
                if(event.scale < MIN_SCALE){
39
                    console.log("tohle je moc")
40
                    scale.value = MIN_SCALE
41
                }
42
                else{
43
                    scale.value = event.scale;
44
                }
15 45

  
16
    console.log(selectedRoom?.kx, selectedRoom?.ky, selectedRoom?.svg_path)
46
                console.log(scale.value)
47
            }
48
        },
49
    });
17 50

  
18
    console.log(mapImage.viewBox)
51
    const animatedStyle = useAnimatedStyle(() => {
52
        return {
53
            transform: [
54
                { translateX: translateX.value },
55
                { translateY: translateY.value },
56
                { scale: scale.value },
57
            ],
58
        };
59
    });
19 60

  
20 61
    return (
21
        <Box>
22
            {/* Display the background image */}
23
            <SvgXml
24
                xml={mapImage.svg}
25
                height="300"
26

  
27
                preserveAspectRatio="xMidYMid meet"
28
            />
29

  
30
            {/* Display the MapView on top of the background image */}
31
            <MapView
32
                style={{ flex: 1 }}
33
            // Add other map-related props as needed
34
            >
35
            </MapView>
62
        // container
63
        <Box width="100%" height={370} style={{ borderColor: "#F5F5F", borderWidth: 1, overflow: "hidden" }}>
64
            <PinchGestureHandler onGestureEvent={onGestureEvent} simultaneousHandlers={svgRef}>
65
                <Animated.View style={[{
66
                    flex: 1,
67
                }, animatedStyle]}>
68
                    <Svg
69
                        ref={(ref: any) => (svgRef.current = ref)}
70

  
71
                    >
72
                        {mapImage && mapImage.viewBox &&
73
                            // background image                    
74
                            <SvgXml
75
                                xml={mapImage.svg}
76
                                width={"100%"}
77
                                height={"100%"}
78

  
79
                            />}
80

  
81
                    </Svg>
82
                </Animated.View>
83
            </PinchGestureHandler>
36 84
        </Box>
37 85
    );
38
}
86
};
87

  
88
export default CastlePlanView;
39 89

  
40
export default CastlePlanView
src/types/plan.ts
37 37
export type PlanImage = {
38 38
    svg: string,
39 39

  
40
    viewBox?: {
40
    viewBox: {
41 41
        x: number,
42 42
        y: number,
43 43
        width: number,

Také k dispozici: Unified diff