Elevation.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //@flow
  2. import React, { useState, useCallback, useRef, useEffect } from 'react';
  3. import { SafeAreaView, View, Image } from 'react-native';
  4. import ViewShot from 'react-native-view-shot';
  5. import Desc from './Desc';
  6. const dimension = { width: 200, height: 200 };
  7. const ElevationExample = () => {
  8. const [source, setSource] = useState(null);
  9. const [viewHandle, setRefHandle] = useState(null);
  10. const onCapture = useCallback(uri => setSource({ uri }), []);
  11. const viewRef = useRef();
  12. const ref = useRef();
  13. return (
  14. <SafeAreaView>
  15. <ViewShot ref={ref} captureMode="mount" onCapture={onCapture} style={dimension}>
  16. <View
  17. style={{
  18. position: 'absolute',
  19. backgroundColor: 'white',
  20. width: 80,
  21. height: 80,
  22. top: 40,
  23. left: 40,
  24. elevation: 1,
  25. }}
  26. />
  27. <View
  28. style={{
  29. position: 'absolute',
  30. backgroundColor: 'white',
  31. width: 80,
  32. height: 80,
  33. top: 80,
  34. left: 80,
  35. elevation: 4,
  36. }}
  37. />
  38. <View
  39. style={{
  40. position: 'absolute',
  41. backgroundColor: 'white',
  42. width: 10,
  43. height: 10,
  44. top: 20,
  45. left: 140,
  46. elevation: 1,
  47. }}
  48. />
  49. <View
  50. style={{
  51. position: 'absolute',
  52. backgroundColor: 'white',
  53. width: 10,
  54. height: 10,
  55. top: 40,
  56. left: 140,
  57. elevation: 2,
  58. }}
  59. />
  60. <View
  61. style={{
  62. position: 'absolute',
  63. backgroundColor: 'white',
  64. width: 10,
  65. height: 10,
  66. top: 60,
  67. left: 140,
  68. elevation: 3,
  69. }}
  70. />
  71. </ViewShot>
  72. <Desc desc="" />
  73. <Image fadeDuration={0} source={source} style={dimension} />
  74. </SafeAreaView>
  75. );
  76. };
  77. ElevationExample.navigationOptions = {
  78. title: 'Elevation',
  79. };
  80. export default ElevationExample;