Skip to content

Instantly share code, notes, and snippets.

View manusalinas-mx's full-sized avatar
🏠
Working from home

Manu Salinas manusalinas-mx

🏠
Working from home
View GitHub Profile
VStack {
// 03/09/2023, 3:16 PM
Text(Date.now.formatted())
// 3:17:05 PM
Text(Date.now.formatted(date: .omitted, time: .standard))
// Mar 9, 2023 at 3:15:26 PM CST
Text(Date.now.formatted(date: .abbreviated, time: .complete))
import SwiftUI
struct ValidatorViewModifier: ViewModifier {
let value: String
let field: LoginScreen.FormField
@Binding var shouldValidate: Bool
@Binding var validationResults: [LoginScreen.FormField: Bool]
let validationRule: (String) -> String?
@State private var errorMessage: String?
@manusalinas-mx
manusalinas-mx / React Native: Reducer: authReducer.tsx.ts
Created December 9, 2024 21:28
- Context file snippetslab://snippet/0C97FD4D-A88D-42EF-A331-3C4C4DF6143D
import { AuthState } from "./AuthContext";
type AuthAction = { type: "login" } | { type: "logout" } | { type: "changeFavIcon"; payload: string } | { type: "changeUsername"; payload: string; img?: string };
export const authReducer = (state: AuthState, action: AuthAction): AuthState => {
switch (action.type) {
case "login":
return {
...state,
isLoggedIn: true,
@manusalinas-mx
manusalinas-mx / React Native: Context: AuthContext.tsx.ts
Created December 9, 2024 21:28
- Reducer file snippetslab://snippet/C661D7F1-A85F-433A-AF77-F8E527688AA8
import React, { createContext, useReducer } from "react";
import { authReducer } from "./authReducer";
// Definir como luce y que informacion tendra
export interface AuthState {
isLoggedIn: boolean;
username?: string;
imageUrl?: string;
favoriteIcon?: string;
}
@manusalinas-mx
manusalinas-mx / React Native: Context: AuthContext.tsx.ts
Created December 9, 2024 21:28
- Reducer file snippetslab://snippet/C661D7F1-A85F-433A-AF77-F8E527688AA8
import React, { createContext, useReducer } from "react";
import { authReducer } from "./authReducer";
// Definir como luce y que informacion tendra
export interface AuthState {
isLoggedIn: boolean;
username?: string;
imageUrl?: string;
favoriteIcon?: string;
}
@manusalinas-mx
manusalinas-mx / React Native: Reducer: themeReducer.tsx.ts
Created December 9, 2024 21:27
- Context file: snippetslab://snippet/D9284645-C8FB-4F5F-B886-5C763912B36F
export type ThemeAction = { type: "dark_theme_on" } | { type: "light_theme_on" };
export interface ThemeState {
currentTheme: "light" | "dark";
dividerColor: string;
dark: boolean;
colors: {
primary: string;
background: string;
card: string;
// En la iterface solo agrega el tipo
style?: StyleProp<ViewStyle>
// Ejemplo:
interface Props {
imgUrl: string;
style?: StyleProp<ViewStyle>
}
// Implementaiton on ScrollView or Flat List
<ScrollView
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={onRefresh}
progressBackgroundColor={'silver'}
intColor={'purple'}
style={{
setTimeout(() => {
...
}, 3000)
import React, { useState } from "react";
import { View, Switch, Text, StyleSheet } from "react-native";
import { BackButton } from "../../components/BackButton";
import { HeaderTitle } from "../../components/HeaderTitle";
import { CustomSwitch } from "../../components/CustomSwitch";
export const SwitchScreen = () => {
const [state, setState] = useState({
isActive: true,
isHungry: false,