Skip to content

Commit a3118ae

Browse files
committed
(fix) improve image resizing
1 parent 9195c7d commit a3118ae

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/ChatWindow/Room.vue

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
</slot>
210210
</div>
211211
<div class="vac-image-file">
212-
<img ref="imageFile" :src="imageFile" />
212+
<img ref="imageFile" :src="imageFile" @load="onImgLoad" />
213213
</div>
214214
</div>
215215

@@ -478,22 +478,6 @@ export default {
478478
messagesLoaded(val) {
479479
if (val) this.loadingMessages = false
480480
if (this.infiniteState) this.infiniteState.complete()
481-
},
482-
imageFile() {
483-
setTimeout(() => {
484-
if (!this.$refs.imageFile) {
485-
this.imageDimensions = null
486-
setTimeout(() => this.resizeTextarea(), 0)
487-
} else {
488-
let height = this.$refs.imageFile.height
489-
if (height < 30) height = 30
490-
491-
this.imageDimensions = {
492-
height: this.$refs.imageFile.height - 10,
493-
width: this.$refs.imageFile.width + 26
494-
}
495-
}
496-
}, 20)
497481
}
498482
},
499483
@@ -538,6 +522,15 @@ export default {
538522
},
539523
540524
methods: {
525+
onImgLoad() {
526+
let height = this.$refs.imageFile.height
527+
if (height < 30) height = 30
528+
529+
this.imageDimensions = {
530+
height: this.$refs.imageFile.height - 10,
531+
width: this.$refs.imageFile.width + 26
532+
}
533+
},
541534
async recordAudio() {
542535
if (this.recorder.state === 'recording') {
543536
this.recorder.stop()
@@ -622,15 +615,18 @@ export default {
622615
this.editedMessage = {}
623616
this.messageReply = null
624617
this.file = null
618+
this.imageDimensions = null
625619
this.imageFile = null
626620
this.emojiOpened = false
627621
setTimeout(() => this.focusTextarea(disableMobileFocus), 0)
628622
},
629623
resetImageFile() {
624+
this.imageDimensions = null
630625
this.imageFile = null
631626
this.editedMessage.file = null
632627
this.file = null
633628
this.focusTextarea()
629+
setTimeout(() => this.resizeTextarea(), 0)
634630
},
635631
resetTextareaSize() {
636632
if (!this.$refs['roomTextarea']) return

0 commit comments

Comments
 (0)