forked from trussworks/react-file-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from transcom/B-21049
B-21049
- Loading branch information
Showing
11 changed files
with
364 additions
and
466 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @licstart The following is the entire license notice for the | ||
* JavaScript code in this page | ||
* | ||
* Copyright 2024 Mozilla Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @licend The above is the entire license notice for the | ||
* JavaScript code in this page | ||
*/ |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,72 @@ | ||
// Copyright (c) 2017 PlanGrid, Inc. | ||
|
||
import React, { Component } from 'react'; | ||
import React, { Component } from 'react' | ||
|
||
import * as ThreeLib from 'three'; | ||
import PhotoViewer from './photo-viewer'; | ||
import Photo360Viewer from './photo360-viewer'; | ||
import Loading from '../loading'; | ||
import * as ThreeLib from 'three' | ||
import PhotoViewer from './photo-viewer' | ||
import Photo360Viewer from './photo360-viewer' | ||
import Loading from '../loading' | ||
|
||
function getPhotoDriver(width, height, fileType) { | ||
if (fileType === 'jpg' && window.Math.abs((width / height) - 2) <= 0.01) { | ||
return Photo360Viewer; | ||
if (fileType === 'jpg' && window.Math.abs(width / height - 2) <= 0.01) { | ||
return Photo360Viewer | ||
} | ||
return PhotoViewer; | ||
return PhotoViewer | ||
} | ||
|
||
export default class PhotoViewerWrapper extends Component { | ||
constructor(props) { | ||
super(props); | ||
super(props) | ||
|
||
this.state = { | ||
originalWidth: 0, | ||
originalHeight: 0, | ||
imageLoaded: false, | ||
}; | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
// spike on using promises and a different loader or adding three js loading manager | ||
const loader = new ThreeLib.TextureLoader(); | ||
loader.crossOrigin = ''; | ||
const loader = new ThreeLib.TextureLoader() | ||
loader.crossOrigin = '' | ||
// get error handler | ||
var onError = this.props.onError | ||
if (typeof onError == 'undefined' || onError == null) { | ||
onError = (xhr) => { | ||
console.log('An error happened', xhr) | ||
} | ||
} | ||
// load a resource | ||
loader.load( | ||
// resource URL | ||
this.props.filePath, | ||
// Function when resource is loaded | ||
// Function when resource is loaded | ||
(texture) => { | ||
this.setState({ | ||
originalWidth: texture.image.width, | ||
originalHeight: texture.image.height, | ||
imageLoaded: true, | ||
texture, | ||
}); | ||
}, | ||
(xhr) => { | ||
console.log(`${xhr.loaded / xhr.total * 100}% loaded`); | ||
}) | ||
}, | ||
(xhr) => { | ||
console.log('An error happened', xhr); | ||
console.log(`${(xhr.loaded / xhr.total) * 100}% loaded`) | ||
}, | ||
); | ||
onError | ||
) | ||
} | ||
|
||
render() { | ||
if (!this.state.imageLoaded) { | ||
return <Loading />; | ||
return <Loading /> | ||
} | ||
const { originalWidth, originalHeight } = this.state; | ||
const PhotoDriver = getPhotoDriver(originalWidth, originalHeight, this.props.fileType); | ||
const { originalWidth, originalHeight } = this.state | ||
const PhotoDriver = getPhotoDriver( | ||
originalWidth, | ||
originalHeight, | ||
this.props.fileType | ||
) | ||
|
||
return ( | ||
<PhotoDriver {...this.state} {...this.props} /> | ||
); | ||
return <PhotoDriver {...this.state} {...this.props} /> | ||
} | ||
} |
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
Oops, something went wrong.