related-ui-components 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  import {
3
3
  View,
4
4
  Text,
@@ -7,75 +7,126 @@ import {
7
7
  TextStyle,
8
8
  TouchableOpacity,
9
9
  TouchableOpacityProps,
10
- } from 'react-native';
10
+ StyleProp, // Import StyleProp for better type safety
11
+ } from "react-native";
11
12
 
12
- import { Ionicons } from '@expo/vector-icons';
13
+ import { Ionicons } from "@expo/vector-icons"; // Assuming you have this installed
13
14
 
14
15
  interface LockOverlayProps extends TouchableOpacityProps {
15
16
  visible?: boolean;
16
- containerStyle?: ViewStyle;
17
- iconStyle?: ViewStyle;
18
- textStyle?: TextStyle;
19
- text?: string;
17
+ containerStyle?: StyleProp<ViewStyle>; // Style for the main TouchableOpacity overlay
18
+ contentContainerStyle?: StyleProp<ViewStyle>; // Style for the inner View wrapping icon and text
19
+ iconStyle?: StyleProp<TextStyle>; // Ionicons style prop is TextStyle
20
+ textStyle?: StyleProp<TextStyle>;
21
+ text?: string | null; // Text is now optional, null explicitly hides it
22
+ iconName?: string; // Allow customizing the icon
20
23
  iconSize?: number;
21
24
  iconColor?: string;
22
25
  overlayOpacity?: number;
23
- contentVerticalAlign? : 'center' | 'top'
26
+ contentPosition?: "center" | "top-center" | "top-left" | "top-right";
27
+ contentPadding?: number; // Padding from edges for top-left/top-right/top-center
24
28
  }
25
29
 
26
30
  const LockOverlay: React.FC<LockOverlayProps> = ({
27
31
  visible = true,
28
32
  containerStyle,
33
+ contentContainerStyle,
29
34
  iconStyle,
30
35
  textStyle,
31
- text = 'Unlock',
36
+ text = "Unlock", // Default text, but can be null or empty
37
+ iconName = "lock-closed",
32
38
  iconSize = 50,
33
- iconColor = 'white',
39
+ iconColor = "white",
34
40
  overlayOpacity = 0.7,
35
- contentVerticalAlign = "center",
41
+ contentPosition = "center",
42
+ contentPadding = 20, // Default padding for edge positions
36
43
  ...touchableProps
37
44
  }) => {
38
45
  if (!visible) return null;
39
46
 
47
+ const overlayStyles: StyleProp<ViewStyle> = [
48
+ styles.overlayBase,
49
+ { backgroundColor: `rgba(0, 0, 0, ${overlayOpacity})` },
50
+ ];
51
+
52
+ // Apply positioning styles to the main overlay container
53
+ switch (contentPosition) {
54
+ case "top-center":
55
+ overlayStyles.push({
56
+ justifyContent: "flex-start",
57
+ alignItems: "center",
58
+ paddingTop: contentPadding,
59
+ });
60
+ break;
61
+ case "top-left":
62
+ overlayStyles.push({
63
+ justifyContent: "flex-start",
64
+ alignItems: "flex-start",
65
+ paddingTop: contentPadding,
66
+ paddingLeft: contentPadding,
67
+ });
68
+ break;
69
+ case "top-right":
70
+ overlayStyles.push({
71
+ justifyContent: "flex-start",
72
+ alignItems: "flex-end",
73
+ paddingTop: contentPadding,
74
+ paddingRight: contentPadding,
75
+ });
76
+ break;
77
+ case "center":
78
+ default:
79
+ overlayStyles.push({
80
+ justifyContent: "center",
81
+ alignItems: "center",
82
+ });
83
+ break;
84
+ }
85
+
86
+ overlayStyles.push(containerStyle); // Apply user-provided containerStyle last
87
+
40
88
  return (
41
89
  <TouchableOpacity
42
- style={[
43
- styles.overlay,
44
- { backgroundColor: `rgba(0, 0, 0, ${overlayOpacity})` },
45
- contentVerticalAlign == "top" && {justifyContent:"flex-start", paddingTop: 50},
46
- containerStyle,
47
- ]}
90
+ style={overlayStyles}
48
91
  activeOpacity={0.8}
49
92
  {...touchableProps}
50
93
  >
51
- <Ionicons
52
- name="lock-closed"
53
- size={iconSize}
54
- color={iconColor}
55
- // style={iconStyle}
56
- />
57
- <Text style={[styles.text, { color: iconColor }, textStyle]}>
58
- {text}
59
- </Text>
94
+ <View style={[styles.contentContainerBase, contentContainerStyle]}>
95
+ <Ionicons
96
+ name={iconName as any} // Cast to any if Ionicons types are too strict for dynamic names
97
+ size={iconSize}
98
+ color={iconColor}
99
+ style={iconStyle}
100
+ />
101
+ {/* Conditionally render text if it's a non-empty string */}
102
+ {text && text.trim() !== "" && (
103
+ <Text style={[styles.textBase, { color: iconColor }, textStyle]}>
104
+ {text}
105
+ </Text>
106
+ )}
107
+ </View>
60
108
  </TouchableOpacity>
61
109
  );
62
110
  };
63
111
 
64
112
  const styles = StyleSheet.create({
65
- overlay: {
66
- position: 'absolute',
113
+ overlayBase: {
114
+ position: "absolute",
67
115
  top: 0,
68
116
  left: 0,
69
117
  right: 0,
70
118
  bottom: 0,
71
- justifyContent: 'center',
72
- alignItems: 'center',
73
- zIndex: 999,
119
+ zIndex: 999, // Ensure it's on top
120
+ },
121
+ contentContainerBase: {
122
+ // This container ensures icon and text (if present) are aligned relative to each other
123
+ alignItems: "center", // Center text under the icon by default
74
124
  },
75
- text: {
76
- fontSize: 20,
77
- fontWeight: 'bold',
78
- marginTop: 12,
125
+ textBase: {
126
+ fontSize: 18, // Adjusted default size slightly
127
+ fontWeight: "bold",
128
+ marginTop: 10, // Adjusted default margin
129
+ textAlign: "center",
79
130
  },
80
131
  });
81
132