This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const swapLightForDark = (appearance: string) => { | |
switch (appearance) { | |
case 'light': | |
return 'dark'; | |
case 'dark': | |
return 'light'; | |
default: | |
throw new Error('Unknown appearance'); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useCallback } from 'react'; | |
import { StatusBar } from 'react-native'; | |
import { useFocusEffect } from '@react-navigation/native' | |
const useStatusBar = ({ style, backgroundColor, translucent, hidden }) => { | |
useFocusEffect( | |
useCallback(() => { | |
style && StatusBar.setBarStyle(style, true); | |
backgroundColor && StatusBar.setBackgroundColor(backgroundColor, true); | |
translucent && StatusBar.setTranslucent(translucent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {asyncA, asyncB} from './api' | |
const ComponentWithLoading = () => { | |
const [doA, aLoading] = useLoading(asyncA); | |
const [doB, bLoading] = useLoading(asyncB); | |
useEffect(() => { | |
doA(); | |
doB(); | |
}, []); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
const useLoading = (action) => { | |
const [loading, setLoading] = useState(false); | |
const doAction = (...args) => { | |
setLoading(true); | |
return action(...args).finally(() => setLoading(false)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const animation = useSharedValue(0); | |
const animateCircle = (breathing) => { | |
if (!breathing) animation.value = 0; | |
else { | |
animation.value = withRepeat( | |
withTiming(1, { | |
duration: 5000, | |
reverse: true, | |
easing: Easing.inOut(Easing.ease), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
progress.value = withTiming(100, { duration: 1000 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mult = (a, b) => { | |
'worklet'; | |
return a * b; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useCode( | |
() => [ | |
cond(and(not(breathing), clockRunning(clock)), stopClock(clock)), | |
cond( | |
and(not(not(breathing)), not(clockRunning(clock))), | |
startClock(clock) | |
), | |
set(animation, [ | |
loop({ | |
duration: 5000, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ChatView = () = { | |
const wsRef = useWebSocket( | |
'wss://example.com/chat', | |
null, | |
(message) => alert(message), | |
() => alert('error!') | |
); | |
return ( |