-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(foundation): added Placeholder component
- Loading branch information
Showing
16 changed files
with
262 additions
and
17 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
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
46 changes: 46 additions & 0 deletions
46
packages/uikit-react-native-foundation/src/ui/LoadingSpinner/index.tsx
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { Animated, Easing, StyleProp, ViewStyle } from 'react-native'; | ||
|
||
import useUIKitTheme from '../../theme/useUIKitTheme'; | ||
import Icon from '../Icon'; | ||
|
||
type Props = { | ||
size?: number; | ||
color?: string; | ||
style?: StyleProp<ViewStyle>; | ||
}; | ||
|
||
const LoadingSpinner: React.FC<Props> = ({ size = 24, color, style }) => { | ||
const { colors } = useUIKitTheme(); | ||
return ( | ||
<Rotate style={style}> | ||
<Icon icon={'spinner'} size={size} color={color ?? colors.primary} /> | ||
</Rotate> | ||
); | ||
}; | ||
|
||
const useLoopAnimated = (duration: number, useNativeDriver = true) => { | ||
const animated = useRef(new Animated.Value(0)).current; | ||
|
||
useEffect(() => { | ||
Animated.loop( | ||
Animated.timing(animated, { toValue: 1, duration, useNativeDriver, easing: Easing.inOut(Easing.linear) }), | ||
{ resetBeforeIteration: true }, | ||
).start(); | ||
|
||
return () => { | ||
animated.stopAnimation(); | ||
animated.setValue(0); | ||
}; | ||
}, []); | ||
|
||
return animated; | ||
}; | ||
|
||
const Rotate: React.FC<{ style: StyleProp<ViewStyle> }> = ({ children, style }) => { | ||
const loop = useLoopAnimated(1000); | ||
const rotate = loop.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '360deg'] }); | ||
return <Animated.View style={[style, { transform: [{ rotate }] }]}>{children}</Animated.View>; | ||
}; | ||
|
||
export default LoadingSpinner; |
70 changes: 70 additions & 0 deletions
70
packages/uikit-react-native-foundation/src/ui/Placeholder/index.tsx
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
|
||
import createStyleSheet from '../../styles/createStyleSheet'; | ||
import useUIKitTheme from '../../theme/useUIKitTheme'; | ||
import Button from '../Button'; | ||
import Icon from '../Icon'; | ||
import LoadingSpinner from '../LoadingSpinner'; | ||
import Text from '../Text'; | ||
|
||
type Props = { | ||
loading?: boolean; | ||
|
||
icon: keyof typeof Icon.Assets; | ||
message?: string; | ||
errorRetryLabel?: string; | ||
onPressRetry?: () => void; | ||
}; | ||
|
||
const Placeholder: React.FC<Props> = ({ icon, loading = false, message = '', errorRetryLabel, onPressRetry }) => { | ||
const { colors } = useUIKitTheme(); | ||
|
||
return ( | ||
<View style={loading ? styles.containerLoading : errorRetryLabel ? styles.containerError : styles.container}> | ||
{loading ? ( | ||
<LoadingSpinner size={64} color={colors.ui.placeholder.default.none.highlight} /> | ||
) : ( | ||
<Icon icon={icon} size={64} color={colors.ui.placeholder.default.none.content} /> | ||
)} | ||
{Boolean(message) && !loading && ( | ||
<Text body3 color={colors.ui.placeholder.default.none.content}> | ||
{message} | ||
</Text> | ||
)} | ||
{Boolean(errorRetryLabel) && !loading && ( | ||
<Button | ||
variant={'text'} | ||
onPress={onPressRetry} | ||
contentColor={colors.ui.placeholder.default.none.highlight} | ||
icon={'refresh'} | ||
> | ||
{errorRetryLabel} | ||
</Button> | ||
)} | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = createStyleSheet({ | ||
container: { | ||
width: 200, | ||
height: 100, | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}, | ||
containerError: { | ||
width: 200, | ||
height: 148, | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}, | ||
containerLoading: { | ||
width: 200, | ||
height: 100, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}); | ||
|
||
export default Placeholder; |
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
42 changes: 42 additions & 0 deletions
42
packages/uikit-react-native/src/ui/TypedPlaceholder/index.tsx
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
|
||
import { useLocalization } from '@sendbird/uikit-react-native-core'; | ||
import Placeholder from '@sendbird/uikit-react-native-foundation/src/ui/Placeholder'; | ||
|
||
type Props = { | ||
type: | ||
| 'no-banned-members' | ||
| 'no-channels' | ||
| 'no-messages' | ||
| 'no-muted-members' | ||
| 'no-results-found' | ||
| 'error-wrong' | ||
| 'loading'; | ||
}; | ||
const TypedPlaceholder: React.FC<Props> = ({ type }) => { | ||
const { LABEL } = useLocalization(); | ||
switch (type) { | ||
case 'no-banned-members': | ||
return <Placeholder icon={'ban'} message={LABEL.PLACEHOLDER.NO_BANNED_MEMBERS} />; | ||
case 'no-channels': | ||
return <Placeholder icon={'chat'} message={LABEL.PLACEHOLDER.NO_BANNED_MEMBERS} />; | ||
case 'no-messages': | ||
return <Placeholder icon={'message'} message={LABEL.PLACEHOLDER.NO_BANNED_MEMBERS} />; | ||
case 'no-muted-members': | ||
return <Placeholder icon={'mute'} message={LABEL.PLACEHOLDER.NO_BANNED_MEMBERS} />; | ||
case 'no-results-found': | ||
return <Placeholder icon={'search'} message={LABEL.PLACEHOLDER.NO_BANNED_MEMBERS} />; | ||
case 'error-wrong': | ||
return ( | ||
<Placeholder | ||
icon={'error'} | ||
message={LABEL.PLACEHOLDER.ERROR_SOMETHING_IS_WRONG.MESSAGE} | ||
errorRetryLabel={LABEL.PLACEHOLDER.ERROR_SOMETHING_IS_WRONG.RETRY_LABEL} | ||
/> | ||
); | ||
case 'loading': | ||
return <Placeholder loading icon={'spinner'} />; | ||
} | ||
}; | ||
|
||
export default TypedPlaceholder; |
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
Oops, something went wrong.