-
Notifications
You must be signed in to change notification settings - Fork 24k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RN tester example for filters (#44459)
Summary: Pull Request resolved: #44459 tsia Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D56857709 fbshipit-source-id: 4bbeeed89ec40ca5c9a3472578388699e47f9c9c
- Loading branch information
1 parent
0dceac9
commit 88ab1ce
Showing
4 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
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,188 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet'; | ||
|
||
import React from 'react'; | ||
import {Image, StyleSheet, Text, View} from 'react-native'; | ||
|
||
const hotdog = require('../../assets/hotdog.jpg'); | ||
|
||
type Props = $ReadOnly<{ | ||
style: ViewStyleProp, | ||
}>; | ||
|
||
function StaticViewAndImage(props: Props): React.Node { | ||
return ( | ||
<> | ||
<View style={styles.container}> | ||
<View style={[props.style, styles.commonView]}> | ||
<View style={styles.subview}> | ||
<View style={styles.subsubview} /> | ||
<Text>Hello world!</Text> | ||
</View> | ||
</View> | ||
<View style={styles.commonView}> | ||
<View style={styles.subview}> | ||
<View style={styles.subsubview} /> | ||
<Text>Hello world!</Text> | ||
</View> | ||
</View> | ||
</View> | ||
<View style={styles.container}> | ||
<Image source={hotdog} style={[props.style, styles.commonImage]} /> | ||
<Image source={hotdog} style={styles.commonImage} /> | ||
</View> | ||
</> | ||
); | ||
} | ||
|
||
function StaticViewAndImageWithState(props: Props): React.Node { | ||
const [s, setS] = React.useState(true); | ||
setTimeout(() => setS(!s), 5000); | ||
|
||
return <StaticViewAndImage style={s ? [props.style] : null} />; | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
commonView: { | ||
width: 150, | ||
height: 150, | ||
backgroundColor: '#275752', | ||
}, | ||
commonImage: { | ||
width: 150, | ||
height: 90, | ||
}, | ||
subview: { | ||
width: 75, | ||
height: 75, | ||
backgroundColor: '#8d2b8f', | ||
}, | ||
subsubview: { | ||
width: 38.5, | ||
height: 38.5, | ||
backgroundColor: '#32a840', | ||
}, | ||
container: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-around', | ||
}, | ||
}); | ||
|
||
exports.title = 'Filter'; | ||
exports.category = 'UI'; | ||
exports.description = | ||
'A set of graphical effects that can be applied to a view.'; | ||
exports.examples = [ | ||
{ | ||
title: 'Brightness', | ||
description: 'brightness(1.5)', | ||
render(): React.Node { | ||
return ( | ||
<StaticViewAndImage | ||
style={{experimental_filter: [{brightness: 1.5}]}} | ||
/> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Opacity', | ||
description: 'opacity(0.5)', | ||
render(): React.Node { | ||
return ( | ||
<StaticViewAndImage style={{experimental_filter: [{opacity: 0.5}]}} /> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Contrast', | ||
description: 'contrast(0.5)', | ||
platform: 'android', | ||
render(): React.Node { | ||
return ( | ||
<StaticViewAndImage style={{experimental_filter: [{contrast: 0.5}]}} /> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Sepia', | ||
description: 'sepia(0.5)', | ||
platform: 'android', | ||
render(): React.Node { | ||
return ( | ||
<StaticViewAndImage style={{experimental_filter: [{sepia: 0.5}]}} /> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Grayscale', | ||
description: 'grayscale(0.5)', | ||
platform: 'android', | ||
render(): React.Node { | ||
return ( | ||
<StaticViewAndImage style={{experimental_filter: [{grayscale: 0.5}]}} /> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Saturate', | ||
description: 'saturate(4)', | ||
platform: 'android', | ||
render(): React.Node { | ||
return ( | ||
<StaticViewAndImage style={{experimental_filter: [{saturate: 4}]}} /> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Hue Rotate', | ||
description: 'hueRotate(-90deg)', | ||
platform: 'android', | ||
render(): React.Node { | ||
return ( | ||
<StaticViewAndImage | ||
style={{experimental_filter: [{hueRotate: '-90deg'}]}} | ||
/> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Invert', | ||
description: 'invert(0.7)', | ||
platform: 'android', | ||
render(): React.Node { | ||
return ( | ||
<StaticViewAndImage style={{experimental_filter: [{invert: 0.7}]}} /> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Blur', | ||
description: 'blur(10)', | ||
platform: 'android', | ||
render(): React.Node { | ||
return <StaticViewAndImage style={{experimental_filter: [{blur: 10}]}} />; | ||
}, | ||
}, | ||
{ | ||
title: 'Filters with state updates', | ||
description: 'Turn brightness(1.5) on and off every 5 seconds', | ||
render(): React.Node { | ||
return ( | ||
<StaticViewAndImageWithState | ||
style={{experimental_filter: [{brightness: 1.5}]}} | ||
/> | ||
); | ||
}, | ||
}, | ||
]; |
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