Skip to content

Commit

Permalink
Added image loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuhe committed Nov 12, 2021
1 parent aa72d65 commit d95a250
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 110 deletions.
12 changes: 11 additions & 1 deletion android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
-keep enum org.greenrobot.eventbus.ThreadMode { *; }

# npm - fastimage
-keep public class com.dylanvann.fastimage.* {*;}
-keep public class com.dylanvann.fastimage.** {*;}
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
35 changes: 35 additions & 0 deletions src/components/FastImagePlaceholder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { ReactElement, useState } from 'react'
import { Platform, StyleProp } from 'react-native'
import FastImage, {
Source,
ImageStyle as FastImageStyle,
} from 'react-native-fast-image'

type FastImagePlaceholderProps = {
source: Source | number
style?: StyleProp<FastImageStyle>
placeholder: Source | number
}

function FastImagePlaceholder({
source,
style,
placeholder,
}: FastImagePlaceholderProps): ReactElement {
const isLocalSource = typeof source !== 'number'
const [loading, setLoading] = useState(isLocalSource)

return (
<>
{loading && <FastImage source={placeholder} style={style} />}
<FastImage
source={source}
style={loading ? { flex: 0 } : style}
onLoad={(): void => setLoading(false)}
fallback={Platform.OS === 'android' && isLocalSource}
/>
</>
)
}

export default FastImagePlaceholder
9 changes: 7 additions & 2 deletions src/components/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ const Loading = (props: {
}): ReactElement => {
const size = props.size || 38
return (
<View style={[{ alignItems: 'center' }, props.style]}>
<View
style={[
{ alignItems: 'center', marginBottom: 20 },
props.style,
]}
>
<Image
source={images.loading_circle}
style={{ width: size, height: size, marginBottom: 20 }}
style={{ width: size, height: size }}
/>
</View>
)
Expand Down
7 changes: 2 additions & 5 deletions src/components/TopupLoadingIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { ReactElement } from 'react'
import { View } from 'react-native'
import { Loading } from 'components'

const TopupLoadingIndicator = (): ReactElement => (
<View
<Loading
style={{
position: 'absolute',
flex: 1,
Expand All @@ -12,9 +11,7 @@ const TopupLoadingIndicator = (): ReactElement => (
alignContent: 'center',
justifyContent: 'center',
}}
>
<Loading />
</View>
/>
)

export default TopupLoadingIndicator
4 changes: 1 addition & 3 deletions src/screens/ConfirmPassword/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ const Render = ({
}}
>
{_.some(fee.status) ? (
<View style={{ marginTop: 20 }}>
<Loading size={24} />
</View>
<Loading style={{ marginTop: 20 }} size={24} />
) : (
<UseStationForm form={form} />
)}
Expand Down
4 changes: 1 addition & 3 deletions src/screens/ConnectToWalletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ const Render = ({
</View>
) : (
<View>
<View style={{ marginBottom: 30 }}>
<Loading />
</View>
<Loading style={{ marginBottom: 30 }} />
<Text style={styles.title} fontType="medium">
Ready to Connect
</Text>
Expand Down
69 changes: 39 additions & 30 deletions src/screens/StakingPersonal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React, { ReactElement, useEffect, useState } from 'react'
import { useStaking, useAuth, User, ValidatorUI } from 'lib'
import {
useStaking,
useAuth,
User,
ValidatorUI,
StakingPersonal as StationStakingPersonal,
StakingUI,
} from 'lib'
import { StackScreenProps } from '@react-navigation/stack'

import { navigationHeaderOptions } from 'components/layout/Header'
import Body from 'components/layout/Body'
import { View } from 'react-native'

import { LAYOUT } from 'consts'

import { RootStackParams } from 'types'

Expand All @@ -19,53 +23,45 @@ type Props = StackScreenProps<RootStackParams, 'Staking'>

const Render = ({
user,
setLoadingComplete,
personal,
ui,
}: {
user?: User
setLoadingComplete: React.Dispatch<React.SetStateAction<boolean>>
personal: StationStakingPersonal
ui?: StakingUI
}): ReactElement => {
const { personal, ui, loading } = useStaking(user)

useEffect(() => {
if (loading === false) {
setLoadingComplete(true)
}
}, [loading])

const findMoniker = ({
name,
}: {
name: string
}): ValidatorUI | undefined =>
ui?.contents.find((x) => x.moniker === name)

return personal ? (
return (
<>
{user && <Rewards personal={personal} user={user} />}
<Delegated personal={personal} findMoniker={findMoniker} />
<UnDelegated personal={personal} findMoniker={findMoniker} />
</>
) : (
<View
style={{
height: LAYOUT.getWindowHeight(),
justifyContent: 'center',
}}
>
<Loading />
</View>
)
}

const StakingPersonal = ({ navigation }: Props): ReactElement => {
const { user } = useAuth()
const { personal, ui, loading } = useStaking(user)
const [loadingComplete, setLoadingComplete] = useState(false)

const [refreshingKey, setRefreshingKey] = useState(0)
const refreshPage = async (): Promise<void> => {
setRefreshingKey((ori) => ori + 1)
}

useEffect(() => {
if (loading === false) {
setLoadingComplete(true)
}
}, [loading])

useEffect(() => {
let unsubscribe
if (loadingComplete) {
Expand All @@ -80,14 +76,27 @@ const StakingPersonal = ({ navigation }: Props): ReactElement => {
<Body
theme={'sky'}
containerStyle={{ paddingTop: 20 }}
scrollable
scrollable={loadingComplete}
onRefresh={refreshPage}
>
<Render
key={refreshingKey}
user={user}
setLoadingComplete={setLoadingComplete}
/>
{loadingComplete ? (
personal && (
<Render
user={user}
personal={personal}
ui={ui}
key={refreshingKey}
/>
)
) : (
<Loading
style={{
flex: 1,
height: '100%',
justifyContent: 'center',
}}
/>
)}
</Body>
)
}
Expand Down
8 changes: 5 additions & 3 deletions src/screens/TabStaking/ValidatorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Preferences, {
} from 'nativeModules/preferences'
import { StakingFilterEnum } from './index'
import { RootStackParams } from 'types'
import FastImagePlaceholder from 'components/FastImagePlaceholder'

const ValidatorList = ({
contents,
Expand Down Expand Up @@ -103,7 +104,7 @@ const ValidatorList = ({
address: item.operatorAddress.address,
})
}
key={`contents${index}`}
key={`validator${index}`}
>
<View
style={{
Expand Down Expand Up @@ -153,16 +154,17 @@ const ValidatorList = ({
</Text>
}
</View>
<FastImage
<FastImagePlaceholder
source={
item.profile
? {
uri: item.profile,
cache: FastImage.cacheControl.immutable,
cache: FastImage.cacheControl.web,
}
: images.terra
}
style={styles.profileImage}
placeholder={images.loading_circle}
/>
{validatorList &&
_.some(
Expand Down
6 changes: 2 additions & 4 deletions src/screens/TabStaking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ const Render = ({
/>
</View>
) : (
<View
<Loading
style={{
height: '100%',
justifyContent: 'center',
}}
>
<Loading />
</View>
/>
)}
</>
)
Expand Down
6 changes: 2 additions & 4 deletions src/screens/TabSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,13 @@ const Swap = (props: Props): ReactElement => {
{...props}
/>
) : (
<View
<Loading
style={{
height: '100%',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Loading />
</View>
/>
)}
</Fragment>
</Body>
Expand Down
6 changes: 4 additions & 2 deletions src/screens/ValidatorDetail/Top.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactElement, useEffect, useState } from 'react'
import { Image, StyleSheet, View } from 'react-native'
import { StyleSheet, View } from 'react-native'
import _ from 'lodash'

import { Text, Icon } from 'components'
Expand All @@ -8,6 +8,7 @@ import { ValidatorUI } from 'lib'
import images from 'assets/images'
import { COLOR } from 'consts'
import useTerraAssets from 'lib/hooks/useTerraAssets'
import FastImagePlaceholder from 'components/FastImagePlaceholder'

const Top = ({ ui }: { ui: ValidatorUI }): ReactElement => {
const { profile, moniker, status, operatorAddress } = ui
Expand All @@ -27,9 +28,10 @@ const Top = ({ ui }: { ui: ValidatorUI }): ReactElement => {
return (
<View style={styles.container}>
<View>
<Image
<FastImagePlaceholder
source={profile ? { uri: profile } : images.terra}
style={styles.profileImage}
placeholder={images.loading_circle}
/>
</View>
<Text style={styles.moniker} fontType={'bold'}>
Expand Down
Loading

0 comments on commit d95a250

Please sign in to comment.