mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d6e0bc714a
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41334 TSIA. Changelog: [Internal] Reviewed By: robhogan Differential Revision: D51025812 fbshipit-source-id: e10d437be775a6b80946483aa96460f34927f870
69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
import type VCTracker, {VisualElement} from './VCTrackerExample';
|
|
|
|
import * as React from 'react';
|
|
import {useEffect, useState} from 'react';
|
|
import {Dimensions, StyleSheet, View} from 'react-native';
|
|
|
|
const OVERLAY_SCALE = 0.25;
|
|
|
|
export default function VCOverlayExample(props: {
|
|
vcTracker: VCTracker,
|
|
}): React.Node {
|
|
const [visualElements, setVisualElements] = useState<
|
|
$ReadOnlyArray<VisualElement>,
|
|
>([]);
|
|
|
|
useEffect(() => {
|
|
setVisualElements(props.vcTracker.getVisualElements());
|
|
props.vcTracker.onUpdateVisualElements(elements => {
|
|
setVisualElements(elements);
|
|
});
|
|
}, [props.vcTracker]);
|
|
|
|
return (
|
|
<View style={styles.overlay}>
|
|
{visualElements.map((visualElement, index) => (
|
|
<View
|
|
key={index}
|
|
style={[
|
|
styles.overlayElement,
|
|
{
|
|
top: visualElement.rect.top * OVERLAY_SCALE,
|
|
left: visualElement.rect.left * OVERLAY_SCALE,
|
|
width: visualElement.rect.width * OVERLAY_SCALE,
|
|
height: visualElement.rect.height * OVERLAY_SCALE,
|
|
},
|
|
]}
|
|
/>
|
|
))}
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
overlay: {
|
|
position: 'absolute',
|
|
bottom: 60,
|
|
right: 10,
|
|
width: OVERLAY_SCALE * Dimensions.get('window').width,
|
|
height: OVERLAY_SCALE * Dimensions.get('window').height,
|
|
backgroundColor: 'gray',
|
|
opacity: 0.9,
|
|
},
|
|
overlayElement: {
|
|
position: 'absolute',
|
|
borderWidth: 1,
|
|
borderColor: 'black',
|
|
},
|
|
});
|