0.1.11 • Published 5 years ago

react-native-image-mapper v0.1.11

Weekly downloads
341
License
MIT
Repository
github
Last release
5 years ago

react-native-image-mapper

React Native component to allow clickable areas on an image

Setup

$ yarn add react-native-image-mapper --save

Usage

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

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Image Mapper } from 'react-native-image-mapper';

const imageSource = require('./path/to/my/image.jpg');
const MAPPING = [
  {
    id: '0',
    name: 'First Area Name',
    shape: 'rectangle',
    width: 30,
    height: 40,
    x1: 80,
    y1: 500,
    prefill: 'red',
    fill: 'blue'
  },
  {
    id: '1',
    name: 'Second Area Name',
    shape: 'rectangle',
    x2: 155,
    y2: 540,
    x1: 125,
    y1: 500
  },
]

class MyReactNativeComponent extends Component {
  // ....
  render() {
    return (
      <ImageMapper
        imgHeight={500}
        imgWidth={250}
        imgSource={imageSource}
        imgMap={MAPPING}
        onPress={(item, idx, event) => this.onAnyAreaPress(item, idx, event)}
        containerStyle={styles.myCustomStyle}
        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

Thanks

Big thanks to Coldiary and his React project

License

Copyright (c) 2019 Marc Salo MIT License See LICENSE for specifics

0.1.11

5 years ago

0.1.10

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.0.2

5 years ago

0.1.0

5 years ago