-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(🐛): fix build regression on fabric (#2769)
- Loading branch information
1 parent
412d3a3
commit aab5771
Showing
7 changed files
with
110 additions
and
122 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,111 @@ | ||
/** | ||
* Sample React Native App | ||
* https://github.com/facebook/react-native | ||
* | ||
* @format | ||
*/ | ||
|
||
import React from "react"; | ||
import type { PropsWithChildren } from "react"; | ||
import React, { useEffect, useMemo } from "react"; | ||
import { StyleSheet, useWindowDimensions, View } from "react-native"; | ||
import { | ||
SafeAreaView, | ||
ScrollView, | ||
StatusBar, | ||
StyleSheet, | ||
Text, | ||
useColorScheme, | ||
View, | ||
} from "react-native"; | ||
BlurMask, | ||
vec, | ||
Canvas, | ||
Circle, | ||
Fill, | ||
Group, | ||
polar2Canvas, | ||
mix, | ||
} from "@shopify/react-native-skia"; | ||
import type { SharedValue } from "react-native-reanimated"; | ||
import { | ||
Colors, | ||
DebugInstructions, | ||
Header, | ||
LearnMoreLinks, | ||
ReloadInstructions, | ||
} from "react-native/Libraries/NewAppScreen"; | ||
cancelAnimation, | ||
Easing, | ||
useDerivedValue, | ||
useSharedValue, | ||
withRepeat, | ||
withTiming, | ||
} from "react-native-reanimated"; | ||
|
||
const useLoop = ({ duration }: { duration: number }) => { | ||
const progress = useSharedValue(0); | ||
useEffect(() => { | ||
progress.value = withRepeat( | ||
withTiming(1, { duration, easing: Easing.inOut(Easing.ease) }), | ||
-1, | ||
true | ||
); | ||
return () => { | ||
cancelAnimation(progress); | ||
}; | ||
}, [duration, progress]); | ||
return progress; | ||
}; | ||
|
||
const c1 = "#61bea2"; | ||
const c2 = "#529ca0"; | ||
|
||
type SectionProps = PropsWithChildren<{ | ||
title: string; | ||
}>; | ||
interface RingProps { | ||
index: number; | ||
progress: SharedValue<number>; | ||
} | ||
|
||
const Ring = ({ index, progress }: RingProps) => { | ||
const { width, height } = useWindowDimensions(); | ||
const R = width / 4; | ||
const center = useMemo( | ||
() => vec(width / 2, height / 2 - 64), | ||
[height, width] | ||
); | ||
|
||
const theta = (index * (2 * Math.PI)) / 6; | ||
const transform = useDerivedValue(() => { | ||
const { x, y } = polar2Canvas( | ||
{ theta, radius: progress.value * R }, | ||
{ x: 0, y: 0 } | ||
); | ||
const scale = mix(progress.value, 0.3, 1); | ||
return [{ translateX: x }, { translateY: y }, { scale }]; | ||
}, [progress, R]); | ||
|
||
function Section({ children, title }: SectionProps): React.JSX.Element { | ||
const isDarkMode = useColorScheme() === "dark"; | ||
return ( | ||
<View style={styles.sectionContainer}> | ||
<Text | ||
style={[ | ||
styles.sectionTitle, | ||
{ | ||
color: isDarkMode ? Colors.white : Colors.black, | ||
}, | ||
]} | ||
> | ||
{title} | ||
</Text> | ||
<Text | ||
style={[ | ||
styles.sectionDescription, | ||
{ | ||
color: isDarkMode ? Colors.light : Colors.dark, | ||
}, | ||
]} | ||
> | ||
{children} | ||
</Text> | ||
</View> | ||
<Circle | ||
c={center} | ||
r={R} | ||
color={index % 2 ? c1 : c2} | ||
origin={center} | ||
transform={transform} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
function App(): React.JSX.Element { | ||
const isDarkMode = useColorScheme() === "dark"; | ||
export const Breathe = () => { | ||
const { width, height } = useWindowDimensions(); | ||
const center = useMemo( | ||
() => vec(width / 2, height / 2 - 64), | ||
[height, width] | ||
); | ||
|
||
const backgroundStyle = { | ||
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, | ||
}; | ||
const progress = useLoop({ duration: 3000 }); | ||
|
||
const transform = useDerivedValue( | ||
() => [{ rotate: mix(progress.value, -Math.PI, 0) }], | ||
[progress] | ||
); | ||
|
||
return ( | ||
<SafeAreaView style={backgroundStyle}> | ||
<StatusBar | ||
barStyle={isDarkMode ? "light-content" : "dark-content"} | ||
backgroundColor={backgroundStyle.backgroundColor} | ||
/> | ||
<ScrollView | ||
contentInsetAdjustmentBehavior="automatic" | ||
style={backgroundStyle} | ||
> | ||
<Header /> | ||
<View | ||
style={{ | ||
backgroundColor: isDarkMode ? Colors.black : Colors.white, | ||
}} | ||
> | ||
<Section title="Step One"> | ||
Edit <Text style={styles.highlight}>App.tsx</Text> to change this | ||
screen and then come back to see your edits. | ||
</Section> | ||
<Section title="See Your Changes"> | ||
<ReloadInstructions /> | ||
</Section> | ||
<Section title="Debug"> | ||
<DebugInstructions /> | ||
</Section> | ||
<Section title="Learn More"> | ||
Read the docs to discover what to do next: | ||
</Section> | ||
<LearnMoreLinks /> | ||
</View> | ||
</ScrollView> | ||
</SafeAreaView> | ||
<View style={{ flex: 1 }}> | ||
<Canvas style={styles.container}> | ||
<Fill color="rgb(36,43,56)" /> | ||
<Group origin={center} transform={transform} blendMode="screen"> | ||
<BlurMask style="solid" blur={40} /> | ||
{new Array(6).fill(0).map((_, index) => { | ||
return <Ring key={index} index={index} progress={progress} />; | ||
})} | ||
</Group> | ||
</Canvas> | ||
</View> | ||
); | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default Breathe; | ||
|
||
const styles = StyleSheet.create({ | ||
sectionContainer: { | ||
marginTop: 32, | ||
paddingHorizontal: 24, | ||
}, | ||
sectionTitle: { | ||
fontSize: 24, | ||
fontWeight: "600", | ||
}, | ||
sectionDescription: { | ||
marginTop: 8, | ||
fontSize: 18, | ||
fontWeight: "400", | ||
}, | ||
highlight: { | ||
fontWeight: "700", | ||
container: { | ||
flex: 1, | ||
}, | ||
}); | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default App; |
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
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
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