-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* π Fix bridge.imageLoader is deprecated #92 * π Fix deprecated imports
- Loading branch information
1 parent
471a4e0
commit 926b55e
Showing
3 changed files
with
110 additions
and
93 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,98 +1,119 @@ | ||
import * as React from "react"; | ||
import { requireNativeComponent, processColor, Platform, View } from "react-native"; | ||
import { | ||
requireNativeComponent, | ||
processColor, | ||
Platform, | ||
View | ||
} from "react-native"; | ||
import * as PropTypes from "prop-types"; | ||
const resolveAssetSource = require("react-native/Libraries/Image/resolveAssetSource"); | ||
const ImageSourcePropType = require("react-native/Libraries/Image/ImageSource"); | ||
import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource"; | ||
import ImageSourcePropType from "react-native/Libraries/DeprecatedPropTypes/DeprecatedImageSourcePropType"; | ||
class MerryPhotoView extends React.Component { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
* Handle UIColor conversions | ||
* @param data Photo[] | ||
*/ | ||
this.processor = (data) => { | ||
if (data && data.length) { | ||
return data.map(o => { | ||
const d = { ...o }; | ||
if (typeof o.summaryColor === "string") { | ||
d.summaryColor = processColor(o.summaryColor); | ||
} | ||
if (typeof o.titleColor === "string") { | ||
d.titleColor = processColor(o.titleColor); | ||
} | ||
// resolve assets | ||
d.source = resolveAssetSource(o.source); | ||
return d; | ||
}); | ||
} | ||
return data; | ||
}; | ||
this.onChange = (event) => { | ||
const { onChange } = this.props; | ||
if (onChange) { | ||
const { target, ...rest } = event.nativeEvent; | ||
onChange(rest); | ||
} | ||
}; | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
* Handle UIColor conversions | ||
* @param data Photo[] | ||
*/ | ||
this.processor = data => { | ||
if (data && data.length) { | ||
return data.map(o => { | ||
const d = { ...o }; | ||
if (typeof o.summaryColor === "string") { | ||
d.summaryColor = processColor(o.summaryColor); | ||
} | ||
if (typeof o.titleColor === "string") { | ||
d.titleColor = processColor(o.titleColor); | ||
} | ||
// resolve assets | ||
d.source = resolveAssetSource(o.source); | ||
return d; | ||
}); | ||
} | ||
return data; | ||
}; | ||
this.onChange = event => { | ||
const { onChange } = this.props; | ||
if (onChange) { | ||
const { target, ...rest } = event.nativeEvent; | ||
onChange(rest); | ||
} | ||
}; | ||
} | ||
render() { | ||
// nothing | ||
if (this.props.visible === false) { | ||
return null; | ||
} | ||
render() { | ||
// nothing | ||
if (this.props.visible === false) { | ||
return null; | ||
} | ||
const { visible, data, initial, ...props } = this.props; | ||
const dataCopy = [...data]; | ||
const transformData = this.processor(dataCopy); | ||
// initial | ||
let startPosition = initial; | ||
if (initial < 0) { | ||
startPosition = 0; | ||
} | ||
if (initial > dataCopy.length) { | ||
startPosition = dataCopy.length; | ||
} | ||
return (<RNMerryPhotoView {...props} initial={startPosition} data={transformData} onChange={this.onChange}/>); | ||
const { visible, data, initial, ...props } = this.props; | ||
const dataCopy = [...data]; | ||
const transformData = this.processor(dataCopy); | ||
// initial | ||
let startPosition = initial; | ||
if (initial < 0) { | ||
startPosition = 0; | ||
} | ||
if (initial > dataCopy.length) { | ||
startPosition = dataCopy.length; | ||
} | ||
return ( | ||
<RNMerryPhotoView | ||
{...props} | ||
initial={startPosition} | ||
data={transformData} | ||
onChange={this.onChange} | ||
/> | ||
); | ||
} | ||
} | ||
MerryPhotoView.propTypes = { | ||
data: PropTypes.arrayOf(PropTypes.shape({ | ||
source: Platform.OS === "ios" | ||
? ImageSourcePropType | ||
: PropTypes.oneOfType([ | ||
data: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
source: | ||
Platform.OS === "ios" | ||
? ImageSourcePropType | ||
: PropTypes.oneOfType([ | ||
PropTypes.shape({ | ||
uri: PropTypes.string, | ||
headers: PropTypes.objectOf(PropTypes.string) | ||
}), | ||
// Opaque type returned by require('./image.jpg') | ||
PropTypes.number, | ||
// Multiple sources | ||
PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
uri: PropTypes.string, | ||
headers: PropTypes.objectOf(PropTypes.string) | ||
}), | ||
// Opaque type returned by require('./image.jpg') | ||
PropTypes.number, | ||
// Multiple sources | ||
PropTypes.arrayOf(PropTypes.shape({ | ||
uri: PropTypes.string, | ||
width: PropTypes.number, | ||
height: PropTypes.number | ||
})) | ||
uri: PropTypes.string, | ||
width: PropTypes.number, | ||
height: PropTypes.number | ||
}) | ||
) | ||
]), | ||
title: PropTypes.string, | ||
summary: PropTypes.string, | ||
titleColor: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
summaryColor: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) | ||
})).isRequired, | ||
visible: PropTypes.bool, | ||
initial: PropTypes.number.isRequired, | ||
hideStatusBar: PropTypes.bool, | ||
hideCloseButton: PropTypes.bool, | ||
hideShareButton: PropTypes.bool, | ||
onDismiss: PropTypes.func.isRequired, | ||
onChange: PropTypes.func, | ||
shareText: PropTypes.string, | ||
...View.propTypes | ||
title: PropTypes.string, | ||
summary: PropTypes.string, | ||
titleColor: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
summaryColor: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) | ||
}) | ||
).isRequired, | ||
visible: PropTypes.bool, | ||
initial: PropTypes.number.isRequired, | ||
hideStatusBar: PropTypes.bool, | ||
hideCloseButton: PropTypes.bool, | ||
hideShareButton: PropTypes.bool, | ||
onDismiss: PropTypes.func.isRequired, | ||
onChange: PropTypes.func, | ||
shareText: PropTypes.string, | ||
...View.propTypes | ||
}; | ||
MerryPhotoView.defaultProps = { | ||
visible: false | ||
visible: false | ||
}; | ||
var RNMerryPhotoView = requireNativeComponent("MerryPhotoView", MerryPhotoView, { | ||
var RNMerryPhotoView = requireNativeComponent( | ||
"MerryPhotoView", | ||
MerryPhotoView, | ||
{ | ||
nativeOnly: { | ||
onChange: true | ||
onChange: true | ||
} | ||
}); | ||
} | ||
); | ||
export default MerryPhotoView; |
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