1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = void 0;
|
7 |
|
8 | var _react = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _reactNative = require("react-native");
|
11 |
|
12 | var _awsAmplify = require("aws-amplify");
|
13 |
|
14 | var _AmplifyTheme = _interopRequireDefault(require("../AmplifyTheme"));
|
15 |
|
16 | var _S3Image = _interopRequireDefault(require("./S3Image"));
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
19 |
|
20 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
21 |
|
22 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
23 |
|
24 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
25 |
|
26 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
27 |
|
28 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
29 |
|
30 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
31 |
|
32 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
33 |
|
34 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
35 |
|
36 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
37 |
|
38 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
39 |
|
40 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
41 |
|
42 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
43 |
|
44 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
45 |
|
46 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
47 |
|
48 | var logger = new _awsAmplify.Logger('Storage.S3Album');
|
49 |
|
50 | var S3Album = function (_Component) {
|
51 | _inherits(S3Album, _Component);
|
52 |
|
53 | var _super = _createSuper(S3Album);
|
54 |
|
55 | function S3Album(props) {
|
56 | var _this;
|
57 |
|
58 | _classCallCheck(this, S3Album);
|
59 |
|
60 | _this = _super.call(this, props);
|
61 | _this.state = {
|
62 | images: []
|
63 | };
|
64 | return _this;
|
65 | }
|
66 |
|
67 | _createClass(S3Album, [{
|
68 | key: "componentDidMount",
|
69 | value: function componentDidMount() {
|
70 | var _this2 = this;
|
71 |
|
72 | var _this$props = this.props,
|
73 | path = _this$props.path,
|
74 | level = _this$props.level,
|
75 | filter = _this$props.filter;
|
76 | logger.debug(path);
|
77 |
|
78 | _awsAmplify.Storage.list(path, {
|
79 | level: level ? level : 'public'
|
80 | }).then(function (data) {
|
81 | logger.debug(data);
|
82 |
|
83 | if (filter) {
|
84 | data = filter(data);
|
85 | }
|
86 |
|
87 | _this2.setState({
|
88 | images: data
|
89 | });
|
90 | })["catch"](function (err) {
|
91 | return logger.warn(err);
|
92 | });
|
93 | }
|
94 | }, {
|
95 | key: "render",
|
96 | value: function render() {
|
97 | var images = this.state.images;
|
98 |
|
99 | if (!images) {
|
100 | return null;
|
101 | }
|
102 |
|
103 | var _Dimensions$get = _reactNative.Dimensions.get('window'),
|
104 | width = _Dimensions$get.width,
|
105 | height = _Dimensions$get.height;
|
106 |
|
107 | var theme = this.props.theme || _AmplifyTheme["default"];
|
108 | var albumStyle = Object.assign({}, _reactNative.StyleSheet.flatten(theme.album), {
|
109 | width: '100%',
|
110 | height: height
|
111 | });
|
112 | var list = this.state.images.map(function (image) {
|
113 | return _react["default"].createElement(_S3Image["default"], {
|
114 | key: image.key,
|
115 | imgKey: image.key,
|
116 | resizeMode: "cover",
|
117 | style: {
|
118 | width: '100%',
|
119 | height: width
|
120 | },
|
121 | theme: theme
|
122 | });
|
123 | });
|
124 | return _react["default"].createElement(_reactNative.ScrollView, _extends({}, this.props, {
|
125 | style: albumStyle
|
126 | }), list);
|
127 | }
|
128 | }]);
|
129 |
|
130 | return S3Album;
|
131 | }(_react.Component);
|
132 |
|
133 | exports["default"] = S3Album; |
\ | No newline at end of file |