1.0.0 • Published 6 months ago

react-native-image-mapper-lelli v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

react-native-image-mapper-lelli

React Native component to allow clickable areas on an image

Setup

$ npm i react-native-image-mapper-lelli --save

Usage

Import the ImageMapper component from react-native-image-mapper-lelli and use it as seen below:

import React, { useEffect, useState } from 'react';
import ImageMapper from 'react-native-image-mapper-lelli'

export default function InspeccionDigital() {
  const [imageSource, setImageSource] = useState('');

  useEffect(() => {
    // Obtén una imagen de Lorem Picsum
    const loremPicsumUrl = 'https://picsum.photos/250/500';
    setImageSource(loremPicsumUrl);
  }, []);

  const onAnyAreaPress = (item, idx, event) => {
    // Manejar la lógica cuando se hace clic en cualquier área
    console.log('Área clickeada:', item);
  };

  return (
    <ImageMapper
      imgHeight={500}
      imgWidth={250}
      imgSource={{ uri: imageSource }}
      imgMap={[
        {
          id: 'area1',
          shape: 'rectangle',
          x1: 50,
          y1: 50,
          x2: 150,
          y2: 150,
          fill: 'rgba(255, 0, 0, 0.5)', // Rojo
        },
        {
          id: 'area2',
          shape: 'circle',
          x1: 200,
          y1: 100,
          radius: 30,
          fill: 'rgba(255, 0, 0, 0.5)', // Rojo
        },
      ]}
      onPress={(item, idx, event) => onAnyAreaPress(item, idx, event)}
      selectedAreaId="my_area_id"
    />
  );
}

Properties

Prop NameTypeDescriptionExample
imgSourcestringImage source urlrequired
imgMaparrayMapping for imageSee below
selectedAreaIdstring or arrayID of the currently selected area or array of ids'areaOne' or ['areaOne', 'areaTwo']
imgWidthnumberImage widthDisplayed width
imgHeightnumberImage heightDisplayed height
multiselectbooleanDefaults to false. Allows for tracking of multiple selections.true or false

When multiselect is set to true, selectedAreaId must be an array of ids rather than a string

Props callbacksCalled onSignature
onPressClick on an area in image(item: object, index: number, event: object)

imgMap is an object describing touchable areas in the image.

PropertyTypeDescription
idstringID of the item used for selected or not selected
namestringName of the item
shapestringRequired - Either rectangle or circle
prefillstringrgba(255, 255, 255, 0.5)
fillstringrgba(255, 255, 255, 0.5)
x1numberRequired - Top Left X coordinate in rectangle or Center X coordinate in circle
y1numberRequired - Top Left Y coordinate in rectangle or Center Y coordinate in circle
x2numberRequired for Rectangle unless width (below) is specified - Bottom Left X coordinate in rectangle
y2numberRequired for Rectangle unless height (below) is specified - Bottom Left Y coordinate in rectangle
widthnumberRequired for Rectangle unless x2 (above) is specified - Width of rectangle
heightnumberRequired for Rectangle unless y2 (above) is specified - Height of rectangle
radiusnumberRequired for Circle - Radius of circle

License

Copyright (c) 2023 Franco Lelli MIT License See LICENSE for specifics

1.0.0

6 months ago