Skip to content

Commit

Permalink
(fix): render w/o errors (stray strings, NaN aspect ratio)
Browse files Browse the repository at this point in the history
- never got these errors before the upgrade

- one error was text outside of a Text element
  - oddly enough, narrowed these down to the existence checks before
    rendering an element
    - made them strictly bools
- another was aspectRatio being NaN initialy due to 0/0 defaults
  - set them to null default instead and added them to existence checks
    before rendering the image
  • Loading branch information
agilgur5 committed Oct 24, 2019
1 parent 144c5f4 commit 0472342
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/chapterList.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class ChapterList extends React.Component {
<Text style={styles.title}>
{manga.title.toUpperCase()}
</Text>
{manga.tags.length && <Text style={styles.tags}>
{manga.tags.length > 0 && <Text style={styles.tags}>
{manga.tags.join(', ').toUpperCase()}
</Text>}
<ScrollView>
Expand Down
8 changes: 5 additions & 3 deletions components/pageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export default class PageList extends React.Component {
class Page extends React.PureComponent {
state = {
image: null,
imageWidth: 0,
imageHeight: 0
imageWidth: null,
imageHeight: null
}

componentWillMount () {
Expand All @@ -114,6 +114,8 @@ class Page extends React.PureComponent {
render () {
const { toggleNav } = this.props
const { image, imageWidth, imageHeight } = this.state
const canRender = image && Number.isInteger(imageWidth) &&
Number.isInteger(imageHeight)

const { height, width } = Dimensions.get('window')
// aspectRatio will be > 1, so set width instead of height
Expand All @@ -124,7 +126,7 @@ class Page extends React.PureComponent {
...styles.page,
...{ height, width }
}}>
{image && <Image
{canRender && <Image
style={{
...imageSize,
aspectRatio: imageWidth / imageHeight
Expand Down

0 comments on commit 0472342

Please sign in to comment.