-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Avatar component * Flow fixes * CR fix * Changed avatar examples
- Loading branch information
Showing
12 changed files
with
216 additions
and
22 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
--- | ||
id: avatar | ||
title: Avatar | ||
--- | ||
|
||
Avatar component. | ||
|
||
![Avatar component](assets/avatar.png) | ||
|
||
Example usage: | ||
```javascript | ||
<Avatar initials="CK" size={30} /> | ||
``` | ||
|
||
## Props | ||
|
||
### `initials` (optional) | ||
**type:** `string` | ||
|
||
String to be displayed inside Avatar. | ||
**default value:** '' | ||
|
||
### `onPress` (optional) | ||
**type:** `void => void` | ||
|
||
onPress event handler. | ||
|
||
### `size` (optional) | ||
**type:** `number` | ||
|
||
Size of an Avatar. | ||
|
||
### `style` (optional) | ||
**type:** `Object` | ||
|
||
Custom styles to apply to Avatar. | ||
|
||
### `theme` (optional) | ||
**type:** [`Theme`](theme.html) | ||
|
||
Custom theme for component. By default provided by the ThemeProvider. | ||
|
||
### `url` (optional) | ||
**type:** `string` | ||
|
||
Url pointing to remote avatar image. |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* @flow */ | ||
import * as React from 'react'; | ||
import { View, StyleSheet } from 'react-native'; | ||
|
||
import { Avatar, withTheme, Body } from 'react-native-ios-kit'; | ||
|
||
import type { Theme } from 'react-native-ios-kit/types'; | ||
|
||
type Props = { | ||
theme: Theme, | ||
}; | ||
|
||
class AvatarExample extends React.Component<Props> { | ||
render() { | ||
return ( | ||
<View> | ||
<View style={styles.row}> | ||
<Body>Default</Body> | ||
<Avatar /> | ||
</View> | ||
<View style={styles.row}> | ||
<Body>Url prop</Body> | ||
<Avatar url="https://callstack.com/static/favicon.png" /> | ||
</View> | ||
<View style={styles.row}> | ||
<Body>Initials</Body> | ||
<Avatar initials="CK" /> | ||
</View> | ||
<View style={styles.row}> | ||
<Body>With onPress handler</Body> | ||
<Avatar | ||
url="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQCIl1UiHXVbyY2UVAWE6aflhrlA7CN8BGv4Ej7lkWp0wnJtody" | ||
onPress={() => alert('Hello')} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
export default withTheme(AvatarExample); | ||
|
||
const styles = StyleSheet.create({ | ||
row: { | ||
flexDirection: 'row', | ||
padding: 10, | ||
borderBottomColor: '#333', | ||
borderBottomWidth: StyleSheet.hairlineWidth, | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
}, | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,91 @@ | ||
/* @flow */ | ||
import * as React from 'react'; | ||
import { | ||
StyleSheet, | ||
Image, | ||
ImageBackground, | ||
View, | ||
Text, | ||
TouchableOpacity, | ||
} from 'react-native'; | ||
|
||
import type { Theme } from '../types/Theme'; | ||
import { withTheme } from '../'; | ||
import type { StyleObj } from 'react-native/Libraries/StyleSheet/StyleSheetTypes'; | ||
|
||
type Props = { | ||
theme: Theme, | ||
initials: string, | ||
url?: string, | ||
size: number, | ||
style?: StyleObj, | ||
onPress?: void => void, | ||
}; | ||
|
||
class Avatar extends React.Component<Props> { | ||
static defaultProps = { | ||
initials: '', | ||
size: 50, | ||
}; | ||
|
||
renderTouchableAvatar = () => { | ||
const styles = getStyles(this.props.size); | ||
return ( | ||
<TouchableOpacity style={styles.avatar} onPress={this.props.onPress}> | ||
{this.renderAvatar()} | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
renderAvatar = () => { | ||
const { url, style, initials, size } = this.props; | ||
const styles = getStyles(size); | ||
|
||
if (url) { | ||
return <Image style={[styles.avatar, style]} source={{ uri: url }} />; | ||
} | ||
const overlay = require('../assets/avatartGradient.png'); | ||
return ( | ||
<ImageBackground | ||
imageStyle={[styles.avatar]} | ||
style={[styles.avatar, style]} | ||
source={overlay} | ||
> | ||
<View style={styles.letterWrapper}> | ||
<Text style={styles.letters}>{initials.slice(0, 2)}</Text> | ||
</View> | ||
</ImageBackground> | ||
); | ||
}; | ||
|
||
render() { | ||
const { onPress } = this.props; | ||
if (onPress) return this.renderTouchableAvatar(); | ||
return this.renderAvatar(); | ||
} | ||
} | ||
|
||
export default withTheme(Avatar); | ||
|
||
const getStyles = (avatarSize: number) => | ||
StyleSheet.create({ | ||
letterWrapper: { | ||
height: avatarSize, | ||
width: avatarSize, | ||
borderRadius: avatarSize / 2, | ||
justifyContent: 'center', | ||
backgroundColor: 'transparent', | ||
}, | ||
letters: { | ||
fontSize: avatarSize / 2.4, | ||
fontFamily: 'ArialRoundedMTBold', | ||
textAlign: 'center', | ||
backgroundColor: 'transparent', | ||
color: 'white', | ||
}, | ||
avatar: { | ||
width: avatarSize, | ||
height: avatarSize, | ||
borderRadius: avatarSize / 2, | ||
}, | ||
}); |
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