Skip to content

Commit

Permalink
Merge pull request #7 from TaskRatchet/Working
Browse files Browse the repository at this point in the history
splash screen update
  • Loading branch information
narthur authored Jan 10, 2024
2 parents 6a1e1b1 + acb79f6 commit a8e1a2d
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 52 deletions.
21 changes: 21 additions & 0 deletions .depcheckrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"ignores": [
"@tsconfig/react-native",
"@react-navigation/native-stack",
"babel-preset-react-native",
"expo-dev-client",
"punycode",
"@babel/core",
"@babel/preset-env",
"@babel/preset-flow",
"@babel/runtime",
"@types/jest",
"babel-jest",
"fetch-mock",
"jest-localstorage-mock",
"metro-react-native-babel-preset",
"ts-jest",
"typescript",
"node-fetch"
]
}
2 changes: 1 addition & 1 deletion android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="android:windowBackground">#E0B9BB</item>
</style>

</resources>
13 changes: 0 additions & 13 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,6 @@ PODS:
- React-jsinspector (0.72.7)
- React-logger (0.72.7):
- glog
- react-native-encrypted-storage (4.0.3):
- React-Core
- react-native-safe-area-context (4.8.1):
- React-Core
- react-native-secure-key-store (2.0.10):
Expand Down Expand Up @@ -499,9 +497,6 @@ PODS:
- RNScreens (3.29.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- RNVectorIcons (10.0.3):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- SocketRocket (0.6.1)
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -553,7 +548,6 @@ DEPENDENCIES:
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- react-native-encrypted-storage (from `../node_modules/react-native-encrypted-storage`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- react-native-secure-key-store (from `../node_modules/react-native-secure-key-store`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
Expand All @@ -576,7 +570,6 @@ DEPENDENCIES:
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNScreens (from `../node_modules/react-native-screens`)
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
Expand Down Expand Up @@ -640,8 +633,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
React-logger:
:path: "../node_modules/react-native/ReactCommon/logger"
react-native-encrypted-storage:
:path: "../node_modules/react-native-encrypted-storage"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
react-native-secure-key-store:
Expand Down Expand Up @@ -686,8 +677,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-gesture-handler"
RNScreens:
:path: "../node_modules/react-native-screens"
RNVectorIcons:
:path: "../node_modules/react-native-vector-icons"
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

Expand Down Expand Up @@ -725,7 +714,6 @@ SPEC CHECKSUMS:
React-jsiexecutor: c49502e5d02112247ee4526bc3ccfc891ae3eb9b
React-jsinspector: 8baadae51f01d867c3921213a25ab78ab4fbcd91
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
react-native-safe-area-context: cd1169d797a2ef722a00bfc5af10748d5b6c94f9
react-native-secure-key-store: 910e6df6bc33cb790aba6ee24bc7818df1fe5898
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
Expand All @@ -748,7 +736,6 @@ SPEC CHECKSUMS:
RNCAsyncStorage: 618d03a5f52fbccb3d7010076bc54712844c18ef
RNGestureHandler: 32a01c29ecc9bb0b5bf7bc0a33547f61b4dc2741
RNScreens: 3c5b9f4a9dcde752466854b6109b79c0e205dad3
RNVectorIcons: 64e6a523ac30a3241efa9baf1ffbcc5e76ff747a
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
Expand Down
4 changes: 3 additions & 1 deletion ios/mobile/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};

return [super application:application didFinishLaunchingWithOptions:launchOptions];
BOOL result = [super application:application didFinishLaunchingWithOptions:launchOptions];
self.window.rootViewController.view.backgroundColor = [UIColor colorWithRed:0.10196 green:0.14510 blue:0.20000 alpha:1.00];
return result;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
Expand Down
36 changes: 8 additions & 28 deletions ios/mobile/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -12,36 +12,16 @@
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<view key="view" autoresizesSubviews="NO" opaque="NO" clearsContextBeforeDrawing="NO" userInteractionEnabled="NO" contentMode="scaleToFill" id="1L6-XZ-uwR">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="mobile" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
<rect key="frame" x="0.0" y="202" width="375" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Powered by React Native" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="MN2-I3-ftu">
<rect key="frame" x="0.0" y="626" width="375" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="bottom" secondItem="MN2-I3-ftu" secondAttribute="bottom" constant="20" id="OZV-Vh-mqD"/>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
<constraint firstItem="MN2-I3-ftu" firstAttribute="centerX" secondItem="Bcu-3y-fUS" secondAttribute="centerX" id="akx-eg-2ui"/>
<constraint firstItem="MN2-I3-ftu" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" id="i1E-0Y-4RG"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="x7j-FC-K8j"/>
</constraints>
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<viewLayoutGuide key="safeArea" id="VQL-mw-5y0"/>
<color key="backgroundColor" red="0.10196" green="0.14510" blue="0.20000" alpha="1" colorSpace="deviceRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="52.173913043478265" y="375"/>
<point key="canvasLocation" x="22" y="100"/>
</scene>
</scenes>
</document>
</document>
23 changes: 14 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as React from 'react';
import {useState} from 'react';
import {enableScreens} from 'react-native-screens';

import {WithSplashScreen} from './components/splash';
import {userType} from './components/types';
import HomeScreen from './screens/HomeScreen';
import LoginScreen from './screens/LoginScreen';
Expand All @@ -25,16 +26,20 @@ export const UserContext = React.createContext({
function App(): JSX.Element {
const [currentUser, setCurrentUser] = useState<userType | null>(null);

const isAppReady = true;

return (
<UserContext.Provider value={{currentUser, setCurrentUser}}>
<NavigationContainer>
<Stack.Navigator initialRouteName="LoginScreen">
<Stack.Screen name="LoginScreen" component={LoginScreen} />
<Stack.Screen name="HomeScreen" component={HomeScreen} />
<Stack.Screen name="ProfileScreen" component={ProfileScreen} />
</Stack.Navigator>
</NavigationContainer>
</UserContext.Provider>
<WithSplashScreen isAppReady={isAppReady}>
<UserContext.Provider value={{currentUser, setCurrentUser}}>
<NavigationContainer>
<Stack.Navigator initialRouteName="LoginScreen">
<Stack.Screen name="LoginScreen" component={LoginScreen} />
<Stack.Screen name="HomeScreen" component={HomeScreen} />
<Stack.Screen name="ProfileScreen" component={ProfileScreen} />
</Stack.Navigator>
</NavigationContainer>
</UserContext.Provider>
</WithSplashScreen>
);
}

Expand Down
102 changes: 102 additions & 0 deletions src/components/splash.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React, {useEffect, useRef, useState} from 'react';
import {Animated} from 'react-native';
import {ImageSourcePropType} from 'react-native';

import logo from '../../assets/images/logo_taskratchet_512_bordered.png';
import {styles} from '../styles/splashStyle';

export function WithSplashScreen({
children,
isAppReady,
}: {
isAppReady: boolean;
children: React.ReactNode;
}) {
return (
<>
{isAppReady && children}

<Splash isAppReady={isAppReady} />
</>
);
}

const LOADING_IMAGE = 'Loading image';
const FADE_IN_IMAGE = 'Fade in image';
const WAIT_FOR_APP_TO_BE_READY = 'Wait for app to be ready';
const FADE_OUT = 'Fade out';
const HIDDEN = 'Hidden';

export const Splash = ({isAppReady}: {isAppReady: boolean}) => {
const containerOpacity = useRef(new Animated.Value(1)).current;
const imageOpacity = useRef(new Animated.Value(0)).current;

const [state, setState] = useState<
| typeof LOADING_IMAGE
| typeof FADE_IN_IMAGE
| typeof WAIT_FOR_APP_TO_BE_READY
| typeof FADE_OUT
| typeof HIDDEN
>(LOADING_IMAGE);

useEffect(() => {
if (state === FADE_IN_IMAGE) {
Animated.timing(imageOpacity, {
toValue: 1,
duration: 1000, // Fade in duration
useNativeDriver: true,
}).start(() => {
setState(WAIT_FOR_APP_TO_BE_READY);
});
}
}, [imageOpacity, state]);

useEffect(() => {
if (state === WAIT_FOR_APP_TO_BE_READY) {
if (isAppReady) {
setState(FADE_OUT);
}
}
}, [isAppReady, state]);

useEffect(() => {
if (state === FADE_OUT) {
Animated.timing(containerOpacity, {
toValue: 0,
duration: 1000, // Fade out duration
delay: 1000, // Minimum time the logo will stay visible
useNativeDriver: true,
}).start(() => {
setState(HIDDEN);
});
}
}, [containerOpacity, state]);

if (state === HIDDEN) {
return null;
}

return (
<Animated.View
collapsable={false}
style={[styles.container, {opacity: containerOpacity}]}>
<Animated.Image
source={logo as ImageSourcePropType}
fadeDuration={0}
onLoad={() => {
setState(FADE_IN_IMAGE);
}}
style={[styles.image, {opacity: imageOpacity}]}
resizeMode="contain"
/>
<Animated.Text style={[styles.title, {opacity: imageOpacity}]}>
TaskRatchet
</Animated.Text>
<Animated.Text style={[styles.text, {opacity: imageOpacity}]}>
{state === LOADING_IMAGE && 'Loading...'}
{state === WAIT_FOR_APP_TO_BE_READY && 'Waiting for app to be ready...'}
{state === FADE_OUT && 'Loading...'}
</Animated.Text>
</Animated.View>
);
};
24 changes: 24 additions & 0 deletions src/styles/splashStyle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {StyleSheet} from 'react-native';

export const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
backgroundColor: '#1A2533',
alignItems: 'center',
justifyContent: 'center',
},
image: {
width: 250,
height: 250,
},
text: {
color: 'white',
fontSize: 10,
marginTop: 16,
},
title: {
color: 'white',
fontSize: 24,
marginTop: 16,
},
});

0 comments on commit a8e1a2d

Please sign in to comment.