forked from jsdf/react-native-htmlview
-
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.
- Loading branch information
Showing
7 changed files
with
54 additions
and
49 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
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,55 +1,56 @@ | ||
var React = require('react'); | ||
var ReactNative = require('react-native'); | ||
var { | ||
import React from 'react'; | ||
import { | ||
Image, | ||
Dimensions, | ||
} = ReactNative; | ||
} from 'react-native'; | ||
|
||
var {width} = Dimensions.get('window'); | ||
const {width} = Dimensions.get('window'); | ||
|
||
var baseStyle = { | ||
const baseStyle = { | ||
backgroundColor: 'transparent', | ||
}; | ||
var ResizableImage = React.createClass({ | ||
getInitialState: function() { | ||
return { | ||
|
||
export default class AutoSizedImage extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
// set width 1 is for preventing the warning | ||
// You must specify a width and height for the image %s | ||
width: this.props.style.width || 1, | ||
height: this.props.style.height || 1, | ||
}; | ||
}, | ||
componentDidMount: function() { | ||
} | ||
|
||
componentDidMount() { | ||
//avoid repaint if width/height is given | ||
if (this.props.style.width || this.props.style.height) { | ||
return; | ||
} | ||
Image.getSize(this.props.source.uri, (w, h) => { | ||
this.setState({width: w, height: h}); | ||
}); | ||
}, | ||
render: function() { | ||
var finalSize = {}; | ||
} | ||
|
||
render() { | ||
const finalSize = {}; | ||
if (this.state.width > width) { | ||
finalSize.width = width; | ||
var ratio = width / this.state.width; | ||
const ratio = width / this.state.width; | ||
finalSize.height = this.state.height * ratio; | ||
} | ||
var style = Object.assign( | ||
const style = Object.assign( | ||
baseStyle, | ||
this.props.style, | ||
this.state, | ||
finalSize | ||
); | ||
var source = {}; | ||
let source = {}; | ||
if (!finalSize.width || !finalSize.height) { | ||
source = Object.assign(source, this.props.source, this.state); | ||
} else { | ||
source = Object.assign(source, this.props.source, finalSize); | ||
} | ||
|
||
return <Image style={style} source={source} />; | ||
}, | ||
}); | ||
|
||
module.exports = ResizableImage; | ||
} | ||
} |
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 +1,3 @@ | ||
module.exports = require('./HTMLView'); | ||
import HTMLView from './HTMLView'; | ||
|
||
export default HTMLView; |
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