diff --git a/react-native-comparison-slider-example/ComparisonSlider.js b/react-native-comparison-slider-example/ComparisonSlider.js index e6eab55b..06e46653 100644 --- a/react-native-comparison-slider-example/ComparisonSlider.js +++ b/react-native-comparison-slider-example/ComparisonSlider.js @@ -6,9 +6,10 @@ import { ImageBackground, } from "react-native"; -// @Copyright: jeanregisser +// @Copyright: jeanregisser // MIT: https://github.com/jeanregisser/react-native-slider import Slider from "react-native-slider"; +import Video from 'react-native-video'; // @Copyright: jhampton // MIT: https://github.com/jhampton/react-native-cropping.git @@ -20,8 +21,8 @@ const CroppedImage = function(props) { width: props.cropWidth, backgroundColor: "transparent" }, props.style]}> - - + + + + ); +} + export default class ComparisonSlider extends Component { constructor(props) { @@ -50,8 +77,8 @@ export default class ComparisonSlider extends Component { const rightImage = props.rightImage; if(props.rightImageURI && !props.imageWidth && !props.imageHeight) { - Image.getSize(props.rightImageURI, (width, height) => this.setState({ - imgWidth: width, + Image.getSize(props.rightImageURI, (width, height) => this.setState({ + imgWidth: width, imgHeight: height, cropWidth: width * initialPosition + thumbWidth / 2, })); } @@ -69,8 +96,9 @@ export default class ComparisonSlider extends Component { } } - onChange(value) { + + onChange(value) { const newValue = ((value * 100 * this.state.imgWidth) / 100); if(this.props.onValueChange) { this.props.onValueChange(value); @@ -89,14 +117,14 @@ export default class ComparisonSlider extends Component { const defaultStyle ={ left: (this.state.value * this.state.imgWidth), - width: 2, - height: this.state.imgHeight / 2 - ballSize / 2, - backgroundColor: color, + width: 2, + height: this.state.imgHeight / 2 - ballSize / 2, + backgroundColor: color, position: "absolute", borderWidth: 1, borderColor: color, borderRadius: ballSize / 2, - } + } const defaultStyleTriangle = { width: 0, @@ -112,16 +140,16 @@ export default class ComparisonSlider extends Component { } return ( - - - - + + defaultStyleTriangle, + { + left: ballSize / 20, + transform: [{ rotate: "90deg"}], + }]} + /> - + - {/** Line **/} + {/** Line **/} - + ) } render() { - if(this.props.thumnailRender && !this.props.thumbnailWidth) { - console.log("When using thumbnail render, thumbnailWidth should be specified! "); - } + if (this.props.video) { + return ( + + + + ); + } else { + if(this.props.thumnailRender && !this.props.thumbnailWidth) { + console.log("When using thumbnail render, thumbnailWidth should be specified! "); + } + + return ( + + + + + + + { this.props.thumnailRender && this.props.thumbnailWidth ? + {this.props.thumnailRender()} : + + this.renderDefaultThumbView() } + + this.onChange(value) } + onSlidingStart={() => this.props.onSlidingStart && this.props.onSlidingStart()} + onSlidingComplete={() => this.props.onSlidingComplete && this.props.onSlidingComplete()} + minimumTrackTintColor={this.state.sliderTrackColor} + maximumTrackTintColor={this.state.sliderTrackColor} + // thumbImage={require("./img/left.jpeg")} + thumbTouchSize={{ + width: this.state.thumbWidth * 33, + height: this.state.imgHeight + }} + thumbStyle={{ + backgroundColor: "transparent", + width: this.state.thumbWidth, + height: this.state.imgHeight, + + }} + style={{ + zIndex: 3, + position: "absolute", + width: this.state.imgWidth, + }} + /> + + + ); + } + - return ( - - - - - - - { this.props.thumnailRender && this.props.thumbnailWidth ? - {this.props.thumnailRender()} : - - this.renderDefaultThumbView() } - - this.onChange(value) } - onSlidingStart={() => this.props.onSlidingStart && this.props.onSlidingStart()} - onSlidingComplete={() => this.props.onSlidingComplete && this.props.onSlidingComplete()} - minimumTrackTintColor={this.state.sliderTrackColor} - maximumTrackTintColor={this.state.sliderTrackColor} - // thumbImage={require("./img/left.jpeg")} - thumbTouchSize={{ - width: this.state.thumbWidth * 33, - height: this.state.imgHeight - }} - thumbStyle={{ - backgroundColor: "transparent", - width: this.state.thumbWidth, - height: this.state.imgHeight, - - }} - style={{ - zIndex: 3, - position: "absolute", - width: this.state.imgWidth, - }} - /> - - - ); } } diff --git a/react-native-comparison-slider-example/android/app/build.gradle b/react-native-comparison-slider-example/android/app/build.gradle index 7a02e3c4..fc135570 100644 --- a/react-native-comparison-slider-example/android/app/build.gradle +++ b/react-native-comparison-slider-example/android/app/build.gradle @@ -133,6 +133,7 @@ android { } dependencies { + compile project(':react-native-video') compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.android.support:appcompat-v7:23.0.1" compile "com.facebook.react:react-native:+" // From node_modules diff --git a/react-native-comparison-slider-example/android/app/src/main/java/com/comparisonslider/MainApplication.java b/react-native-comparison-slider-example/android/app/src/main/java/com/comparisonslider/MainApplication.java index a24080d2..9acc67e3 100644 --- a/react-native-comparison-slider-example/android/app/src/main/java/com/comparisonslider/MainApplication.java +++ b/react-native-comparison-slider-example/android/app/src/main/java/com/comparisonslider/MainApplication.java @@ -3,6 +3,7 @@ import android.app.Application; import com.facebook.react.ReactApplication; +import com.brentvatne.react.ReactVideoPackage; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; @@ -22,7 +23,8 @@ public boolean getUseDeveloperSupport() { @Override protected List getPackages() { return Arrays.asList( - new MainReactPackage() + new MainReactPackage(), + new ReactVideoPackage() ); } }; diff --git a/react-native-comparison-slider-example/android/settings.gradle b/react-native-comparison-slider-example/android/settings.gradle index 8e983520..937b27ad 100644 --- a/react-native-comparison-slider-example/android/settings.gradle +++ b/react-native-comparison-slider-example/android/settings.gradle @@ -1,3 +1,5 @@ rootProject.name = 'ComparisonSlider' +include ':react-native-video' +project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android') include ':app' diff --git a/react-native-comparison-slider-example/index.ios.js b/react-native-comparison-slider-example/index.ios.js index 4d3b271a..87047917 100644 --- a/react-native-comparison-slider-example/index.ios.js +++ b/react-native-comparison-slider-example/index.ios.js @@ -13,10 +13,10 @@ import { } from "react-native"; -import ComparisonSlider from "./ComparisonSlider.js"; +import ComparisonSlider from "./ComparisonSlider"; export default class Index extends Component { - + constructor(props) { super(props); @@ -29,15 +29,17 @@ export default class Index extends Component { {/** Local images **/} - + resizeMode="cover" + video={true} + leftImage={require("./video/1.mp4")} + rightImage={require("./video/2.mp4")} /> {/** Remote image **/} - {/**