Skip to content

Commit 3ecb566

Browse files
authored
Merge pull request #1610 from StoDevX/fix-ksto-logo-sizing
Fix KSTO logo sizing and add a landscape layout
2 parents 48fbfee + 3220153 commit 3ecb566

File tree

1 file changed

+96
-60
lines changed

1 file changed

+96
-60
lines changed

source/views/streaming/radio.js

Lines changed: 96 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,47 @@ import {TabBarIcon} from '../components/tabbar-icon'
2222
const kstoStream = 'https://cdn.stobcm.com/radio/ksto1.stream/master.m3u8'
2323
const image = require('../../../images/streaming/ksto/ksto-logo.png')
2424

25-
export default class KSTOView extends React.PureComponent {
25+
type Viewport = {
26+
width: number,
27+
height: number,
28+
}
29+
30+
type Props = {}
31+
32+
type State = {
33+
refreshing: boolean,
34+
paused: boolean,
35+
streamError: ?Object,
36+
viewport: Viewport,
37+
}
38+
39+
export default class KSTOView extends React.PureComponent<void, Props, State> {
2640
static navigationOptions = {
2741
tabBarLabel: 'KSTO',
2842
tabBarIcon: TabBarIcon('radio'),
2943
}
3044

31-
player: Video
32-
33-
state: {
34-
refreshing: boolean,
35-
paused: boolean,
36-
streamError: ?Object,
37-
metadata: Object[],
38-
} = {
45+
state = {
3946
refreshing: false,
4047
paused: true,
4148
streamError: null,
42-
metadata: [],
49+
viewport: Dimensions.get('window'),
4350
}
4451

45-
changeControl = () => {
46-
this.setState(state => ({paused: !state.paused}))
52+
componentWillMount() {
53+
Dimensions.addEventListener('change', this.handleResizeEvent)
54+
}
55+
56+
componentWillUnmount() {
57+
Dimensions.removeEventListener('change', this.handleResizeEvent)
4758
}
4859

49-
// callback when HLS ID3 tags change
50-
onTimedMetadata = (data: any) => {
51-
this.setState(() => ({metadata: data}))
52-
console.log(data)
60+
handleResizeEvent = (event: {window: {width: number}}) => {
61+
this.setState(() => ({viewport: event.window}))
62+
}
63+
64+
changeControl = () => {
65+
this.setState(state => ({paused: !state.paused}))
5366
}
5467

5568
// error from react-native-video
@@ -59,25 +72,44 @@ export default class KSTOView extends React.PureComponent {
5972
}
6073

6174
render() {
75+
const sideways = this.state.viewport.width > this.state.viewport.height
76+
77+
const logoWidth = Math.min(
78+
this.state.viewport.width / 1.5,
79+
this.state.viewport.height / 1.75,
80+
)
81+
82+
const logoSize = {
83+
width: logoWidth,
84+
height: logoWidth,
85+
}
86+
6287
return (
63-
<ScrollView>
88+
<ScrollView
89+
contentContainerStyle={[styles.root, sideways && landscape.root]}
90+
>
91+
<View style={[styles.logoWrapper, sideways && landscape.logoWrapper]}>
92+
<Image
93+
source={image}
94+
style={[styles.logo, logoSize]}
95+
resizeMode="contain"
96+
/>
97+
</View>
98+
6499
<View style={styles.container}>
65-
<Logo />
100+
<Title />
101+
66102
<PlayPauseButton
67103
onPress={this.changeControl}
68104
paused={this.state.paused}
69105
/>
70-
{/*<Song />*/}
71-
<Title />
72106

73107
{!this.state.paused
74108
? <Video
75-
ref={ref => (this.player = ref)}
76109
source={{uri: kstoStream}}
77110
playInBackground={true}
78111
playWhenInactive={true}
79112
paused={this.state.paused}
80-
onTimedMetadata={this.onTimedMetadata}
81113
onError={this.onError}
82114
/>
83115
: null}
@@ -87,37 +119,19 @@ export default class KSTOView extends React.PureComponent {
87119
}
88120
}
89121

90-
const Logo = () => {
91-
const viewport = Dimensions.get('window')
92-
const style = {
93-
maxWidth: viewport.width / 1.2,
94-
maxHeight: viewport.height / 2.0,
95-
}
96-
return (
97-
<View style={styles.wrapper}>
98-
<Image source={image} style={style} />
99-
</View>
100-
)
101-
}
102-
103122
const Title = () => {
104-
const style = {fontSize: Dimensions.get('window').height / 30}
105123
return (
106-
<View style={styles.container}>
107-
<Text selectable={true} style={[styles.heading, style]}>
124+
<View style={styles.titleWrapper}>
125+
<Text selectable={true} style={styles.heading}>
108126
St. Olaf College Radio
109127
</Text>
110-
<Text selectable={true} style={[styles.subHeading, style]}>
128+
<Text selectable={true} style={styles.subHeading}>
111129
KSTO 93.1 FM
112130
</Text>
113131
</View>
114132
)
115133
}
116134

117-
// const song = this.state.metadata.length
118-
// ? <Metadata song={this.state.metadata.CHANGEME} />
119-
// : null
120-
121135
class PlayPauseButton extends React.PureComponent {
122136
props: {
123137
paused: boolean,
@@ -147,35 +161,57 @@ class PlayPauseButton extends React.PureComponent {
147161
}
148162

149163
const styles = StyleSheet.create({
164+
root: {
165+
flexDirection: 'column',
166+
alignItems: 'stretch',
167+
justifyContent: 'space-between',
168+
padding: 20,
169+
},
150170
container: {
151171
alignItems: 'center',
172+
flex: 1,
173+
marginTop: 20,
174+
marginBottom: 20,
175+
},
176+
logoWrapper: {
177+
alignItems: 'center',
178+
justifyContent: 'center',
179+
flex: 1,
152180
},
153-
wrapper: {
154-
padding: 10,
181+
logo: {
182+
borderRadius: 6,
183+
borderColor: c.kstoSecondaryDark,
184+
borderWidth: 3,
185+
},
186+
titleWrapper: {
187+
alignItems: 'center',
188+
marginBottom: 20,
155189
},
156190
heading: {
157-
marginTop: 10,
158191
color: c.kstoPrimaryDark,
159-
fontWeight: '500',
192+
fontWeight: '600',
193+
fontSize: 28,
194+
textAlign: 'center',
160195
},
161196
subHeading: {
162197
marginTop: 5,
163-
marginBottom: 10,
164198
color: c.kstoPrimaryDark,
165199
fontWeight: '300',
200+
fontSize: 28,
201+
textAlign: 'center',
202+
},
203+
})
204+
205+
const landscape = StyleSheet.create({
206+
root: {
207+
flex: 1,
208+
padding: 20,
209+
flexDirection: 'row',
210+
alignItems: 'center',
211+
},
212+
logoWrapper: {
213+
flex: 0,
166214
},
167-
// nowPlaying: {
168-
// paddingTop: 10,
169-
// fontSize: Dimensions.get('window').height / 40,
170-
// fontWeight: '500',
171-
// color: c.red,
172-
// },
173-
// metadata: {
174-
// fontSize: Dimensions.get('window').height / 40,
175-
// paddingHorizontal: 13,
176-
// paddingTop: 5,
177-
// color: c.red,
178-
// },
179215
})
180216

181217
const buttonStyles = StyleSheet.create({

0 commit comments

Comments
 (0)