mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-13 09:30:23 +08:00
40 lines
833 B
JavaScript
40 lines
833 B
JavaScript
import React, { StyleSheet, Text, View } from 'react-native'
|
|
|
|
const MediaQueryWidget = ({ mediaQuery = {} }) => {
|
|
const active = Object.keys(mediaQuery).reduce((active, alias) => {
|
|
if (mediaQuery[alias].matches) {
|
|
active = {
|
|
alias,
|
|
mql: mediaQuery[alias]
|
|
}
|
|
}
|
|
return active
|
|
}, {})
|
|
|
|
return (
|
|
<View style={styles.root}>
|
|
<Text style={styles.heading}>Active Media Query</Text>
|
|
<Text style={styles.text}>{`"${active.alias}"`} {active.mql && active.mql.media}</Text>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
root: {
|
|
alignItems: 'center',
|
|
borderWidth: 1,
|
|
marginVertical: 10,
|
|
padding: 10
|
|
},
|
|
heading: {
|
|
fontWeight: 'bold',
|
|
padding: 5,
|
|
textAlign: 'center'
|
|
},
|
|
text: {
|
|
textAlign: 'center'
|
|
}
|
|
})
|
|
|
|
export default MediaQueryWidget
|