![](/style/images/good.png)
![](/style/images/bad.png)
Compare any two components side-by-side for react native
source link: https://reactnativeexample.com/compare-any-two-components-side-by-side-for-react-native/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
React Native Compare Slider
Compare any two components side-by-side
Features
- Supports images and any other React components (
picture
,video
,canvas
,iframe
etc.) - Supports landscape and portrait orientations
- Customization
Try it out
You can run examples by performing these steps:
$ git clone [email protected]:taranisag/react-native-compare-slider.git
$ npm install
$ npm start android
Installation
$ npm install react-native-compare-slider
Props
Prop
Type
Required
Default value
Description
before
ReactNode
✓
undefined
First component to show in slider.
after
ReactNode
✓
undefined
Second component to show in slider.
containerSize
{ width: number; height: number; }
✓
{100%, 100%}
Container dimensions.
sliderSize
{ width: number; height: number; }
{50, 50}
Slider's handle dimensions.
SliderComponent
ReactNode
undefined
Slider's handle component.
sliderStyles
ViewStyle
undefined
Slider's handle styles.
showSeparationLine
boolean
undefined
Separation line visibility.
separationLineStyles
ViewStyle
undefined
Separation line styles.
Basic Image Usage
import { CompareSlider } from 'react-native-compare-slider';
<CompareSlider
before={<Image source={imageBefore} resizeMode="cover" />}
after={<Image source={imageAfter} resizeMode="cover" />}
containerSize={{ width: 350, height: 100 }}
/>;
Google Maps Usage
install react-native-maps
library
import { CompareSlider } from 'react-native-compare-slider';
import RNM, { MAP_TYPES, PROVIDER_GOOGLE } from 'react-native-maps';
<CompareSlider
before={
<RNM
provider={PROVIDER_GOOGLE}
mapType={MAP_TYPES.SATELLITE}
initialRegion={{
latitude: 33.61099089454942,
longitude: -90.79735743461134,
latitudeDelta: 1,
longitudeDelta: 1,
}}
/>
}
after={
<RNM
provider={PROVIDER_GOOGLE}
mapType={MAP_TYPES.STANDARD}
initialRegion={{
latitude: 33.61099089454942,
longitude: -90.79735743461134,
latitudeDelta: 1,
longitudeDelta: 1,
}}
/>
}
containerSize={{ width: 300, height: 200 }}
/>;
Customization Usage
import { CompareSlider } from 'react-native-compare-slider';
<CompareSlider
before={<Image source={imageBefore} resizeMode="cover" />}
after={<Image source={imageAfter} resizeMode="cover" />}
sliderStyles={{ backgroundColor: 'green' }}
showSeparationLine={false}
containerSize={{ width: 350, height: 100 }}
/>;
Custom Slider
import { CompareSlider } from 'react-native-compare-slider';
const sliderSize = { width: 70, height: 70 };
const styles = StyleSheet.create({
slider: {
...sliderSize,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(255, 255, 255, 0.75)',
},
sliderText: {
fontSize: 25,
},
});
<CompareSlider
before={<Image source={imageBefore} />}
after={<Image source={imageAfter} />}
sliderSize={sliderSize}
SliderComponent={
<View style={styles.slider}>
<Text style={styles.sliderText}>{'< >'}</Text>
</View>
}
showSeparationLine={false}
containerSize={{ width: 350, height: 100 }}
/>;
Requirements
- React 16.13+
- React Native 0.63+
Recommend
-
7
Two attempts to compare a TLA+ spec with a C++ implementationAt MongoDB, we use TLA+ to specify some of the protocols we use in both the MongoDB server and MongoDB Realm Sync. Forma...
-
7
How to Statistically Compare Two Net Promoter Scores This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you,...
-
15
Compare two consecutive elements in std :: list advertisements I'd like to compare two consecutive elements in a std::list while iterating thr...
-
2
Compare two addresses that are not in standard format advertisements I have to compare addresses from two tables and get the Id if the address...
-
9
[Golang] Compare the Size of Two Files April 08, 2018 This post shows how...
-
3
In this article, we will learn to compare two NumPy Arrays element-wise using Python. Table Of Contents There are the multiple ways to compare two NumPy Arrays element-wise. Let’s discuss them one by one.
-
2
How to Compare Two Proportions with the N−1 Two-Proportion Test Jeff Sauro,...
-
9
How to compare two strings in PHP 10234 views 2 years ago PHP Use the PHP strcmp() function
-
5
Unleash the Power of Server-Side Rendering with React Server Components and Next.js 13An overview of the final implementation of this feature
-
7
How to Compare Two Json Objects Using C#
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK