Skip to content

Commit

Permalink
shows android crash
Browse files Browse the repository at this point in the history
  • Loading branch information
andreialecu committed Sep 3, 2021
1 parent 2b574f3 commit c2afa0f
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 6 deletions.
17 changes: 11 additions & 6 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {enableScreens} from 'react-native-screens';

import Albums from './Albums';
import {TabScreenContext} from './context';
import {Crash} from './Crash';

declare const global: {HermesInternal: null | {}};

Expand Down Expand Up @@ -84,13 +85,17 @@ const TabScreen = () => {
};

const HomeScreen = ({navigation}) => {
console.log('test');
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Pressable style={{backgroundColor: 'blue', color: 'white', padding: 20}} onPress={() => navigation.navigate('TabScreen')}>
<Text>Home Screen</Text>
</Pressable>
</View>
<>
<Crash headerMeasurements={{height: 100, top: {value: 50}}} />
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Pressable
style={{backgroundColor: 'blue', color: 'white', padding: 20}}
onPress={() => navigation.navigate('TabScreen')}>
<Text>Home Screen</Text>
</Pressable>
</View>
</>
);
};

Expand Down
85 changes: 85 additions & 0 deletions Crash.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react';
import {Platform, StyleSheet, Text, View, ViewProps} from 'react-native';
import Animated, {
interpolate,
useAnimatedStyle,
useDerivedValue,
} from 'react-native-reanimated';


export function Crash({
home,
alternateTitle,
headerMeasurements,
}: {
home?: boolean;
alternateTitle?: string;
headerMeasurements?: {height: number; top: {value: number}};
}) {
const headerHeight = headerMeasurements?.height;

/** The point at which the logo starts moving up */
const headerYAnimationStart = headerHeight ? headerHeight - 50 : 0;

const alternateTitleOpacity = useDerivedValue(
() =>
!headerHeight
? 0
: interpolate(
Math.abs(headerMeasurements?.top.value || 0),
[headerYAnimationStart, headerHeight],
[0, 1],
Animated.Extrapolate.CLAMP,
),
[headerMeasurements],
);

const titleTranslateY = useDerivedValue(
() => -30 * alternateTitleOpacity.value,
);

const animatedStyleMain = useAnimatedStyle(() => {
return {
opacity: 1 - alternateTitleOpacity.value,
transform: [{translateY: titleTranslateY.value}],
};
}, [headerMeasurements]);

const animatedStyleAlternate = useAnimatedStyle(() => {
return {
opacity: alternateTitleOpacity.value,
transform: [{translateY: titleTranslateY.value}],
};
}, [headerMeasurements]);

return (
<View
style={[
styles.container,
{
alignItems:
Platform.OS === 'ios' ? 'center' : home ? 'center' : 'flex-start',
} as ViewProps,
]}>
<Animated.View style={[styles.textView, animatedStyleMain]}>
<Text style={styles.text} allowFontScaling={false}>
Foo
</Text>
</Animated.View>
<Animated.View style={[styles.altTitleView, animatedStyleAlternate]}>
<Text style={styles.altTitle}>{alternateTitle}</Text>
</Animated.View>
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
overflow: 'hidden',
},
text: {color: 'white', fontWeight: '700'},
textView: {height: 30, marginTop: Platform.OS === 'ios' ? 4 : 10},
altTitle: {color: 'white', fontWeight: '500'},
altTitleView: {height: 30},
});

0 comments on commit c2afa0f

Please sign in to comment.