1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict'
|
7 |
|
8 | import React, {PropTypes as types} from 'react'
|
9 | import classnames from 'classnames'
|
10 | import {ApImage} from 'apeman-react-image'
|
11 | import {ApTouchable} from 'apeman-react-touchable'
|
12 |
|
13 |
|
14 | const ApPhoto = React.createClass({
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | propTypes: {
|
21 |
|
22 | imgSrc: types.string.isRequired,
|
23 |
|
24 | imgWidth: types.number,
|
25 |
|
26 | imgHeight: types.number,
|
27 |
|
28 | imgScale: types.string,
|
29 |
|
30 | onTap: types.func
|
31 | },
|
32 |
|
33 | mixins: [],
|
34 |
|
35 | statics: {},
|
36 |
|
37 | getInitialState () {
|
38 | return {}
|
39 | },
|
40 |
|
41 | getDefaultProps () {
|
42 | return {
|
43 | imgSrc: null,
|
44 | imgWidth: 256,
|
45 | imgHeight: 128,
|
46 | imgScale: 'fit',
|
47 | onTap: null
|
48 | }
|
49 | },
|
50 |
|
51 | render () {
|
52 | const s = this
|
53 | let { props } = s
|
54 |
|
55 | let { imgWidth, imgHeight } = props
|
56 |
|
57 | let className = classnames('ap-photo', {
|
58 | 'ap-photo-tappable': s.isTappable()
|
59 | }, props.className)
|
60 | return (
|
61 | <div className={ className }
|
62 | style={ Object.assign({}, props.style) }>
|
63 | <ApTouchable onTap={ s.handleTap }>
|
64 | <div>
|
65 | <ApImage src={ props.imgSrc }
|
66 | width={ imgWidth }
|
67 | height={ imgHeight }
|
68 | scale={ props.imgScale }
|
69 | />
|
70 | { props.children }
|
71 | </div>
|
72 | </ApTouchable>
|
73 | </div>
|
74 | )
|
75 | },
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | handleTap (e) {
|
86 | const s = this
|
87 | let { props } = s
|
88 | if (!s.isTappable()) {
|
89 | return
|
90 | }
|
91 | if (props.onTap) {
|
92 | props.onTap(e)
|
93 | }
|
94 | },
|
95 |
|
96 | isTappable () {
|
97 | const s = this
|
98 | let { props } = s
|
99 | return !!props.onTap
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | })
|
106 |
|
107 | export default ApPhoto
|