1+ import React from 'react' ;
2+ import { Dimensions , StyleSheet , Text , View } from 'react-native' ;
3+ import { useSelector } from 'react-redux' ;
4+
5+ interface WatermarkProps {
6+ text ?: string ;
7+ opacity ?: number ;
8+ rotate ?: string ;
9+ colors ?: string [ ] ;
10+ }
11+ /**
12+ * A component used to add watermark effects to the application.
13+ * @param {WatermarkProps } props - Properties for the watermark component
14+ * @param {string } props.text
15+ * @param {number } props.opacity
16+ * @param {string } props.rotate
17+ */
18+ const Watermark : React . FC < WatermarkProps > = ( props ) => {
19+ // 从Redux状态中获取水印设置
20+ const { text, opacity, rotate, colors } = useSelector ( state => state . WatermarkReducer ) ;
21+ const { width, height } = Dimensions . get ( 'window' ) ;
22+ const rows = Math . ceil ( height / 100 ) ;
23+ const cols = Math . ceil ( width / 200 ) ;
24+
25+ return (
26+ < View style = { styles . container } >
27+ { Array . from ( { length : rows } ) . map ( ( _ , rowIndex ) =>
28+ Array . from ( { length : cols } ) . map ( ( _ , colIndex ) => (
29+ < View
30+ key = { `${ rowIndex } -${ colIndex } ` }
31+ style = { [
32+ styles . watermarkItem ,
33+ {
34+ top : rowIndex * 100 ,
35+ left : colIndex * 200 ,
36+ opacity,
37+ transform : [ { rotate } ] ,
38+ } ,
39+ ] } >
40+ < Text >
41+ { text }
42+ </ Text >
43+ </ View >
44+ ) )
45+ ) }
46+ </ View >
47+ ) ;
48+ } ;
49+
50+ const styles = StyleSheet . create ( {
51+ container : {
52+ position : 'absolute' ,
53+ top : 0 ,
54+ left : 0 ,
55+ right : 0 ,
56+ bottom : 0 ,
57+ pointerEvents : 'none' ,
58+ } ,
59+ watermarkItem : {
60+ position : 'absolute' ,
61+ justifyContent : 'center' ,
62+ alignItems : 'center' ,
63+ } ,
64+ gradient : {
65+ padding : 8 ,
66+ borderRadius : 4 ,
67+ fontSize : 16 ,
68+ } ,
69+ } ) ;
70+
71+ export default Watermark ;
0 commit comments