Skip to content

Commit ce33d77

Browse files
authored
Merge pull request #2191 from StoDevX/hawken-credits-custom-icon
Hawken's tweaks to the credits-custom-icon PR
2 parents 34bf01e + abf4273 commit ce33d77

File tree

3 files changed

+79
-54
lines changed

3 files changed

+79
-54
lines changed

images/icon-images.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
// @flow
22

33
export const icons = {
4-
oldMain: require('./about/IconTrans.png'),
5-
windmill: require('../ios/AllAboutOlaf/windmill-icon/windmill.png'),
4+
oldMain: require('./about/IconTrans.png'),
5+
windmill: require('../ios/AllAboutOlaf/windmill-icon/windmill.png'),
6+
}
7+
8+
export const defaultIcon = icons.oldMain
9+
10+
// eslint-disable camelcase
11+
export const iosToNamedIconsMap: {[key: string]: $Keys<typeof icons>} = {
12+
icon_type_windmill: 'windmill',
13+
default: 'oldMain',
14+
}
15+
// eslint-enable camelcase
16+
17+
export function lookup(iosIconName: $Keys<typeof iosToNamedIconsMap>): number {
18+
const iconName = iosToNamedIconsMap[iosIconName]
19+
if (!iconName) {
20+
return defaultIcon
21+
}
22+
23+
const icon = icons[iconName]
24+
if (!icon) {
25+
return defaultIcon
26+
}
27+
28+
return icon
629
}

source/views/components/logo.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// @flow
2+
3+
import * as React from 'react'
4+
import * as Icons from '@hawkrives/react-native-alternate-icons'
5+
import glamorous from 'glamorous-native'
6+
7+
import {lookup as getAppIcon} from '../../../images/icon-images'
8+
9+
const LogoImage = glamorous.image({
10+
width: 100,
11+
height: 100,
12+
alignSelf: 'center',
13+
})
14+
15+
type Props = {
16+
style?: StyleSheet,
17+
}
18+
19+
type State = {
20+
icon: number,
21+
}
22+
23+
export class AppLogo extends React.Component<Props, State> {
24+
state = {
25+
icon: getAppIcon('default'),
26+
}
27+
28+
async componentWillMount() {
29+
const name = await Icons.getIconName()
30+
console.warn(name)
31+
this.setState(() => ({icon: getAppIcon(name)}))
32+
}
33+
34+
render() {
35+
console.warn(this.state.icon)
36+
return <LogoImage source={this.state.icon} style={this.props.style} />
37+
}
38+
}

source/views/settings/credits.js

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,14 @@ import {data as credits} from '../../../docs/credits.json'
55
import glamorous from 'glamorous-native'
66
import {Platform} from 'react-native'
77
import {iOSUIKit, material} from 'react-native-typography'
8-
9-
import {icons as appIcons} from '../../../images/icon-images'
10-
import * as Icons from '@hawkrives/react-native-alternate-icons'
11-
import type {TopLevelViewPropsType} from '../types'
8+
import {AppLogo} from '../components/logo'
129

1310
const Container = glamorous.scrollView({
1411
backgroundColor: c.white,
1512
paddingHorizontal: 5,
1613
paddingVertical: 10,
1714
})
1815

19-
const Logo = glamorous.image({
20-
width: 100,
21-
height: 100,
22-
alignSelf: 'center',
23-
})
24-
2516
const Title = glamorous.text({
2617
textAlign: 'center',
2718
marginTop: 10,
@@ -58,49 +49,22 @@ const Contributors = glamorous(About)({
5849

5950
const formatPeopleList = arr => arr.map(w => w.replace(' ', ' ')).join(' • ')
6051

61-
type Props = TopLevelViewPropsType
62-
63-
type State = {
64-
iconType: null | string,
65-
}
66-
67-
export default class CreditsView extends React.Component<Props, State> {
68-
static navigationOptions = {
69-
title: 'Credits',
70-
}
52+
export default function CreditsView() {
53+
return (
54+
<Container contentInsetAdjustmentBehavior="automatic">
55+
<AppLogo />
7156

72-
state = {
73-
iconType: null,
74-
}
57+
<Title>{credits.name}</Title>
58+
<About>{credits.content}</About>
7559

76-
componentWillMount() {
77-
this.getIcon()
78-
}
60+
<Heading>Contributors</Heading>
61+
<Contributors>{formatPeopleList(credits.contributors)}</Contributors>
7962

80-
getIcon = async () => {
81-
const name = await Icons.getIconName()
82-
this.setState(() => ({iconType: name}))
83-
}
84-
85-
render() {
86-
const image =
87-
this.state.iconType === 'default' ? appIcons.oldMain : appIcons.windmill
88-
89-
return (
90-
<Container contentInsetAdjustmentBehavior="automatic">
91-
<Logo source={image} />
92-
93-
<Title>{credits.name}</Title>
94-
<About>{credits.content}</About>
95-
96-
<Heading>Contributors</Heading>
97-
<Contributors>{formatPeopleList(credits.contributors)}</Contributors>
98-
99-
<Heading>Acknowledgements</Heading>
100-
<Contributors>
101-
{formatPeopleList(credits.acknowledgements)}
102-
</Contributors>
103-
</Container>
104-
)
105-
}
63+
<Heading>Acknowledgements</Heading>
64+
<Contributors>{formatPeopleList(credits.acknowledgements)}</Contributors>
65+
</Container>
66+
)
67+
}
68+
CreditsView.navigationOptions = {
69+
title: 'Credits',
10670
}

0 commit comments

Comments
 (0)