@s20.ai/safecam-360-rn-lite
Version:
A React Native component to view the interior panorama and exterior 360 degree views of a product featuring suppport for hotspots. Compatible with Android and iOS
144 lines (137 loc) • 3.82 kB
JavaScript
/*
* Copyright © 2022 S20.AI India Pvt. Ltd.
* Contact - origin@s20.ai
* License - Licensed as per https://docs.s20.ai/license.html
*/
import React from 'react';
import {View} from 'react-native';
import {useDispatch} from 'react-redux';
import {setCurrentHotspot} from '../../redux/actions/currentHotspotAction';
import {IconButton, Label} from '@s20.ai/safecam-components-rn';
import styleConfig from '../styleConfig';
import {triggerHapticFeedback} from '../../utils/device';
import constants from '../../config/constants';
const HotspotElement = ({
hotspot,
width,
height,
address,
hotspotType,
hotspotLocation,
enableHotspotTooltip,
hotspotPressed,
customFontFamily,
}) => {
const dispatch = useDispatch();
return (
<View
style={{
flexDirection: 'row',
height: 12 * hotspot.display[0],
width: 12 * hotspot.display[0],
//TODO - hotspot positions not exact
// top:
// orientationState.includes(constants.LANDSCAPE)
// ? currentHotspotState
// ? (width / 1.45) * hotspot.y
// : (width / 2.15) * hotspot.y
// : (width / 1.9) * hotspot.y,
top: height * hotspot.y,
left: width * hotspot.x,
position: 'relative',
borderRadius: 50,
justifyContent: 'center',
transform: [
{
translateX: -5,
},
{
translateY: -15,
},
],
}}>
<View
style={{
position: 'absolute',
top: -45,
display: hotspot.display[2] ? 'flex' : 'none',
opacity: hotspot.display[2] ? 1 : 0,
}}>
{enableHotspotTooltip && (
<Label
onPress={() => {
if (hotspotPressed) {
hotspotPressed({
currentView: hotspotLocation,
hotspot: {
title: hotspot.imageTitle,
description: hotspot.description,
},
});
}
dispatch(
setCurrentHotspot({
...hotspot,
address: address,
}),
);
triggerHapticFeedback();
}}
text={hotspot.description || hotspot.imageTitle}
sx={{
...styleConfig.label,
...{
text: {
fontFamily:
customFontFamily && customFontFamily === 'Poppins'
? 'Poppins-SemiBold'
: 'Helvetica',
color: 'black',
},
},
}}
/>
)}
</View>
<IconButton
src={
hotspotType === constants.DAMAGE
? 'https://cars24-images.s3.ap-south-1.amazonaws.com/hotspot.png'
: 'https://cars24-images.s3.ap-south-1.amazonaws.com/feature.png'
}
onPress={() => {
if (hotspotPressed) {
hotspotPressed({
currentView: hotspotLocation,
hotspot: {
type: hotspot.type,
title: hotspot.imageTitle,
description: hotspot.description,
},
});
}
dispatch(
setCurrentHotspot({
...hotspot,
address: address,
}),
);
triggerHapticFeedback();
}}
sx={{
base: {
backgroundColor: 'transparent',
},
icon: {
transform: [
{
scale: 1.65 * hotspot.display[0],
},
],
},
}}
/>
</View>
);
};
export default HotspotElement;