Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import LightboxOverlay from './LightboxOverlay';
export default class Lightbox extends Component {
static propTypes = {
activeProps: PropTypes.object,
openingProps: PropTypes.object,
closingProps: PropTypes.object,
renderHeader: PropTypes.func,
renderContent: PropTypes.func,
underlayColor: PropTypes.string,
Expand Down Expand Up @@ -44,18 +46,16 @@ export default class Lightbox extends Component {
getContent = () => {
if(this.props.renderContent) {
return this.props.renderContent();
} else if(this.props.activeProps) {
return cloneElement(
Children.only(this.props.children),
this.props.activeProps
);
}
}
return this.props.children;
}

getOverlayProps = () => ({
isOpen: this.state.isOpen,
origin: this.state.origin,
activeProps: this.props.activeProps,
openingProps: this.props.openingProps,
closingProps: this.props.closingProps,
renderHeader: this.props.renderHeader,
swipeToDismiss: this.props.swipeToDismiss,
springConfig: this.props.springConfig,
Expand Down
25 changes: 22 additions & 3 deletions LightboxOverlay.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React, { Component, Children, cloneElement } from 'react';
import PropTypes from 'prop-types';
import { Animated, Dimensions, Modal, PanResponder, Platform, StatusBar, StyleSheet, Text, TouchableOpacity, View } from 'react-native';

Expand Down Expand Up @@ -135,6 +135,7 @@ export default class LightboxOverlay extends Component {
this.state.pan.setValue(0);
this.setState({
isAnimating: true,
isOpening: true,
target: {
x: 0,
y: 0,
Expand All @@ -146,7 +147,10 @@ export default class LightboxOverlay extends Component {
this.state.openVal,
{ toValue: 1, ...this.props.springConfig }
).start(() => {
this.setState({ isAnimating: false });
this.setState({
isAnimating: false,
isOpening: false
});
this.props.didOpen();
});
}
Expand All @@ -158,13 +162,15 @@ export default class LightboxOverlay extends Component {
}
this.setState({
isAnimating: true,
isClosing: true,
});
Animated.spring(
this.state.openVal,
{ toValue: 0, ...this.props.springConfig }
).start(() => {
this.setState({
isAnimating: false,
isClosing: false,
});
this.props.onClose();
});
Expand All @@ -176,6 +182,19 @@ export default class LightboxOverlay extends Component {
}
}

getContent = () => {
if (this.state.isOpening && this.props.openingProps) {
return cloneElement(Children.only(this.props.children), this.props.openingProps)
}
else if (this.state.isClosing && this.props.closingProps) {
return cloneElement(Children.only(this.props.children), this.props.closingProps)
}
else if (this.props.activeProps) {
return cloneElement(Children.only(this.props.children), this.props.activeProps)
}
return this.props.children
}

render() {
const {
isOpen,
Expand Down Expand Up @@ -227,7 +246,7 @@ export default class LightboxOverlay extends Component {
)}</Animated.View>);
const content = (
<Animated.View style={[openStyle, dragStyle]} {...handlers}>
{this.props.children}
{this.getContent()}
</Animated.View>
);

Expand Down