Skip to content

Commit 69b0576

Browse files
committed
Made Comments
1 parent 92f22b5 commit 69b0576

File tree

3 files changed

+57
-40
lines changed

3 files changed

+57
-40
lines changed

src/components/common/CustomButton.js

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Text, StyleSheet, View, Pressable } from "react-native";
33
import { colors, paddings, rounded, textStyles } from '../../style';
44
import LoadingDots from "../../animations/LoadingDots";
55

6+
// Define styles for different button types
67
const typeStyles = {
78
primary: { backgroundColor: colors.violet500, textColor: colors.white },
89
secondary: { backgroundColor: colors.grey800, textColor: colors.white },
@@ -19,6 +20,7 @@ const typeStyles = {
1920
},
2021
};
2122

23+
// Define styles for different button states
2224
const stateStyles = {
2325
default: {
2426
primary: { backgroundColor: colors.violet500 },
@@ -52,17 +54,19 @@ const stateStyles = {
5254
},
5355
};
5456

57+
// Define styles for different button sizes
5558
const sizeStyles = {
5659
1: { height: 32, paddingHorizontal: paddings.p_12 },
5760
2: { height: 40, paddingHorizontal: paddings.p_16 },
5861
3: { height: 48, paddingHorizontal: paddings.p_16 },
5962
4: { height: 56, paddingHorizontal: paddings.p_24 },
6063
};
6164

65+
// Function to combine styles based on type, state, and size
6266
const getCombinedStyles = (type, state, size) => {
63-
const typeStyle = typeStyles[type];
64-
const stateStyle = stateStyles[state]?.[type];
65-
const sizeStyle = sizeStyles[size];
67+
const typeStyle = typeStyles[type]; // Get styles based on button type
68+
const stateStyle = stateStyles[state]?.[type]; // Get styles based on button state
69+
const sizeStyle = sizeStyles[size]; // Get styles based on button size
6670

6771
return {
6872
...typeStyle,
@@ -71,28 +75,38 @@ const getCombinedStyles = (type, state, size) => {
7175
};
7276
};
7377

78+
// --------------------------------------------
79+
// CustomButton component definition
80+
// --------------------------------------------
7481
const CustomButton = ({
75-
containerStyle,
76-
onPress,
77-
text = "",
78-
type = "secondary",
79-
size = 4,
80-
leftIcon,
81-
rightIcon,
82-
loading = false,
83-
disabled = false,
84-
scaling = "full",
82+
containerStyle, // Custom styles for the button container
83+
onPress, // Function to call when the button is pressed
84+
text = "", // Text to display on the button
85+
type = "secondary", // Button type (primary, secondary, tertiary, ghost)
86+
size = 4, // Button size (1 to 4)
87+
leftIcon, // Icon to display on the left side of the button
88+
rightIcon, // Icon to display on the right side of the button
89+
loading = false, // Whether the button is in a loading state
90+
disabled = false, // Whether the button is disabled
91+
scaling = "full", // Scaling option for the button
8592
}) => {
93+
// State to manage button state (default, pressed, etc.)
8694
const [buttonState, setButtonState] = useState('default');
87-
const state = loading ? 'loading' : (disabled ? 'disabled' : buttonState);
88-
const combinedStyles = getCombinedStyles(type, state, size);
95+
const state = loading ? 'loading' : (disabled ? 'disabled' : buttonState); // Determine the current state of the button
96+
const combinedStyles = getCombinedStyles(type, state, size); // Get the combined styles based on type, state, and size
8997

98+
// --------------------------------------------
99+
// Handlers for button press events
100+
// --------------------------------------------
101+
102+
// Set state to pressed when the button is pressed in
90103
const handlePressIn = () => {
91104
if (!disabled && !loading) {
92105
setButtonState('pressed');
93106
}
94107
};
95108

109+
// Set state to default when the button is released
96110
const handlePressOut = () => {
97111
if (!disabled && !loading) {
98112
setButtonState('default');
@@ -101,64 +115,68 @@ const CustomButton = ({
101115

102116
const handlePress = () => {
103117
if (!disabled && !loading && onPress) {
104-
onPress();
118+
onPress(); // Call the onPress function when the button is pressed
105119
}
106120
};
107121

122+
// --------------------------------------------
123+
// Render the button
124+
// --------------------------------------------
108125
return (
109126
<Pressable
110127
style={[
111128
{
112-
backgroundColor: combinedStyles.backgroundColor,
113-
height: combinedStyles.height,
114-
borderWidth: combinedStyles.borderWidth || 0,
115-
borderColor: combinedStyles.borderColor || "transparent",
116-
paddingHorizontal: combinedStyles.paddingHorizontal,
129+
backgroundColor: combinedStyles.backgroundColor, // Set background color based on combined styles
130+
height: combinedStyles.height, // Set height based on combined styles
131+
borderWidth: combinedStyles.borderWidth || 0, // Set border width based on combined styles
132+
borderColor: combinedStyles.borderColor || "transparent", // Set border color based on combined styles
133+
paddingHorizontal: combinedStyles.paddingHorizontal, // Set horizontal padding based on combined styles
117134
borderRadius: rounded.rounded_md,
118135
alignItems: "center",
119136
justifyContent: "center",
120-
...(scaling === "full" ? { flexGrow: 1 } : { alignSelf: "flex-start" }),
121-
maxHeight: combinedStyles.height,
137+
...(scaling === "full" ? { flexGrow: 1 } : { alignSelf: "flex-start" }), // Sets scaling based on `scaling`: `auto` adjusts to font size, otherwise it ajusts to the container.
138+
maxHeight: combinedStyles.height, // Set max height based on combined styles
122139
},
123-
containerStyle,
140+
containerStyle, // Apply custom container styles
124141
]}
125-
onPress={handlePress}
126-
onPressIn={handlePressIn}
127-
onPressOut={handlePressOut}
128-
disabled={disabled || loading}
142+
onPress={handlePress} // Handle button press
143+
onPressIn={handlePressIn} // Handle button press in
144+
onPressOut={handlePressOut} // Handle button press out
145+
disabled={disabled || loading} // Disable button if disabled or loading
129146
>
130147
<View style={styles.contentContainer}>
131-
{leftIcon && <View style={styles.iconLeft}>{leftIcon}</View>}
148+
{leftIcon && <View style={styles.iconLeft}>{leftIcon}</View>} {/* Render left icon if provided */}
132149
{loading ? (
133150
<View style={styles.loadingContainer}>
134-
<LoadingDots />
151+
<LoadingDots /> {/* Render loading dots if loading */}
135152
</View>
136153
) : (
137154
<Text style={[styles.text, { color: combinedStyles.textColor, textDecorationLine: combinedStyles.textDecorationLine || "none" }]}>
138-
{text}
155+
{text} {/* Button Text */}
139156
</Text>
140157
)}
141-
{rightIcon && <View style={styles.iconRight}>{rightIcon}</View>}
158+
{rightIcon && <View style={styles.iconRight}>{rightIcon}</View>} {/* Render right icon if provided */}
142159
</View>
143160
</Pressable>
144161
);
145162
};
146163

164+
// Styles for the button content
147165
const styles = StyleSheet.create({
148166
text: {
149-
...textStyles.text_base_bold,
150-
textAlign: "center",
167+
...textStyles.text_base_bold, // Apply base bold text style
168+
textAlign: "center", // Center align text
151169
},
152170
contentContainer: {
153-
flexDirection: "row",
171+
flexDirection: "row", // Arrange content in a row (needed for icons)
154172
alignItems: "center",
155173
justifyContent: "center",
156-
height: "100%",
174+
height: "100%"
157175
},
158176
loadingContainer: {
159177
flexDirection: 'row',
160178
justifyContent: 'center',
161-
alignItems: 'center',
179+
alignItems: 'center'
162180
},
163181
iconLeft: {
164182
marginRight: 8,

src/navigation/AppNavigator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import TopNavigationScreen from '../screens/PreviewScreens/topNavigationScreen';
1616
import NotificationBadgeScreen from '../screens/PreviewScreens/notificationBadgeScreen';
1717
import ButtonIconScreen from '../screens/PreviewScreens/buttonIconScreen';
1818
import CustomCardScreen from '../screens/PreviewScreens/customCardScreen';
19+
import ButtonDockScreen from '../screens/PreviewScreens/buttonDockScreen';
1920

2021
// Icons
2122
import HomeIcon from '../../assets/icons/Navigation/homeIcon';
2223
import TemplatesIcon from '../../assets/icons/Navigation/templateIcon';
2324
import SettingsIcon from '../../assets/icons/Navigation/settingsIcon';
2425
import BackIcon from '../../assets/icons/svg_js/backIcon';
25-
import ButtonDockScreen from '../screens/PreviewScreens/buttonDockScreen';
2626

2727

2828
const MainStack = createNativeStackNavigator();

src/screens/Main/HomeScreen.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { SafeAreaView } from 'react-native-safe-area-context';
44
import { colors, paddings, textStyles } from '../../style';
55
import CustomCard from '../../components/common/CustomCard';
66
import { useNavigation } from '@react-navigation/native';
7-
import PlaceholderIcon from '../../../assets/icons/svg_js/placeholderIcon';
87
import CheckCircleIcon from '../../../assets/icons/svg_js/checkCircleIcon';
98

109
export default function HomeScreen() {
@@ -41,7 +40,7 @@ export default function HomeScreen() {
4140

4241
{/* Button Dock */}
4342
<CustomCard
44-
iconSource={<PlaceholderIcon />}
43+
iconSource={<CheckCircleIcon />}
4544
title="Button Dock"
4645
description="Component"
4746
size="lg"

0 commit comments

Comments
 (0)