1 | import React, { Component, } from 'react';
|
2 | import { Image, Dimensions, Text, View, TouchableWithoutFeedback, } from 'react-native';
|
3 | import Swiper from '../Swiper';
|
4 | import ImageZoom from '../ImageZoom';
|
5 | const DEVICE_WIDTH = Dimensions.get('window').width;
|
6 | const DEVICE_HEIGHT = Dimensions.get('window').height;
|
7 | export class GalleryDefaultProps {
|
8 | constructor() {
|
9 | this.imgs = [];
|
10 | }
|
11 | }
|
12 | const styles = {
|
13 | saveBtn: {
|
14 | position: 'absolute',
|
15 | bottom: 40, right: 20,
|
16 | height: 30,
|
17 | justifyContent: 'center',
|
18 | alignItems: 'center',
|
19 | },
|
20 | cancelBtn: {
|
21 | position: 'absolute',
|
22 | bottom: 40, left: 20,
|
23 | height: 30,
|
24 | justifyContent: 'center',
|
25 | alignItems: 'center',
|
26 | },
|
27 | btnText: {
|
28 | color: 'rgba(255, 255, 255, 0.3)',
|
29 | fontSize: 18,
|
30 | },
|
31 | };
|
32 | export default class Gallery extends Component {
|
33 | constructor() {
|
34 | super(...arguments);
|
35 | this._onSavePress = (uri) => {
|
36 | if (typeof this.props.onSavePress === 'function')
|
37 | this.props.onSavePress(uri);
|
38 | };
|
39 | this._onCancelPress = () => {
|
40 | if (typeof this.props.onCancelPress === 'function')
|
41 | this.props.onCancelPress();
|
42 | };
|
43 | this.renderSavebtn = () => {
|
44 | if (this.props.saveBtn) {
|
45 | return this.props.saveBtn;
|
46 | }
|
47 | return (React.createElement(View, { style: styles.saveBtn },
|
48 | React.createElement(Text, { style: styles.btnText }, "\u4FDD\u5B58\u5230\u624B\u673A")));
|
49 | };
|
50 | this.renderCancelbtn = () => {
|
51 | if (this.props.cancelBtn) {
|
52 | return this.props.cancelBtn;
|
53 | }
|
54 | return (React.createElement(View, { style: styles.cancelBtn },
|
55 | React.createElement(Text, { style: styles.btnText }, "\u5173\u95ED")));
|
56 | };
|
57 | this.renderImgs = () => this.props.imgs.map((img, index) => {
|
58 | const onSavePress = () => this._onSavePress(img.uri);
|
59 | const onCancelPress = () => this._onCancelPress();
|
60 | return (React.createElement(View, { key: index, style: { flex: 1, position: 'relative' } },
|
61 | React.createElement(ImageZoom, { cropWidth: DEVICE_WIDTH, cropHeight: DEVICE_HEIGHT, imageWidth: DEVICE_WIDTH, imageHeight: DEVICE_HEIGHT, panToMove: true },
|
62 | React.createElement(Image, { source: img, style: { flex: 1 }, resizeMode: "contain" })),
|
63 | React.createElement(TouchableWithoutFeedback, { onPress: onSavePress }, this.renderSavebtn()),
|
64 | React.createElement(TouchableWithoutFeedback, { onPress: onCancelPress }, this.renderCancelbtn())));
|
65 | });
|
66 | }
|
67 | render() {
|
68 | return (React.createElement(Swiper, null, this.renderImgs()));
|
69 | }
|
70 | }
|
71 | Gallery.defaultProps = new GalleryDefaultProps();
|
72 |
|
\ | No newline at end of file |