[PLATIR-40656] Check for and execute auto-resize of IAM height, safer use of dispatch async#1122
Conversation
PravinPK
left a comment
There was a problem hiding this comment.
Looks good one minor comment
|
|
||
| // when enabled, this method isn't called until the html is loaded, requiring a redraw with the correct height | ||
| reframeMessage() | ||
| } |
There was a problem hiding this comment.
Can we print a warning log here, just in case if handleAutoResize function fails to reframe message because of casting issues
There was a problem hiding this comment.
I had a question about the implied input format - could you please help me understand why the height is implied to always come in as a String value in this conversion? The JS side would have to know that type contract right?
And would it be simpler to convert to Double or Float instead of Int in the type casting? Since the underlying storage property is a CGFloat anyways
Also instead of checking != 0 can we check that the value is > 0 instead? Guarding against negative values as well
I also agree with the logs point Pravin mentioned, what do you think of something like:
private func handleAutoResize(_ height: Any?) {
if let strHeight = height as? String,
let doubleHeight = Double(strHeight) {
if doubleHeight <= 0 {
Log.debug(label: self.LOG_PREFIX, "Invalid height value received for auto-resize: \(doubleHeight). Height must be positive.")
return
}
fitToContentHeight = CGFloat(doubleHeight)
// when enabled, this method isn't called until the html is loaded, requiring a redraw with the correct height
reframeMessage()
} else {
Log.debug(label: self.LOG_PREFIX, "Failed to parse height value for auto-resize: \(String(describing: height))")
}
}There was a problem hiding this comment.
good suggestions - i'll get this change in
| } | ||
| ] | ||
| }, | ||
| { |
There was a problem hiding this comment.
Sorry if it's a novice question- Is this file auto-generated ?
There was a problem hiding this comment.
Yes I believe it's created using the make api-dump command within the repo
timkimadobe
left a comment
There was a problem hiding this comment.
Thank you Steve! Just had a few questions, and sorry I'm not too familiar with the FullscreenMessage logic and the WebKit interactions yet
|
|
||
| // when enabled, this method isn't called until the html is loaded, requiring a redraw with the correct height | ||
| reframeMessage() | ||
| } |
There was a problem hiding this comment.
I had a question about the implied input format - could you please help me understand why the height is implied to always come in as a String value in this conversion? The JS side would have to know that type contract right?
And would it be simpler to convert to Double or Float instead of Int in the type casting? Since the underlying storage property is a CGFloat anyways
Also instead of checking != 0 can we check that the value is > 0 instead? Guarding against negative values as well
I also agree with the logs point Pravin mentioned, what do you think of something like:
private func handleAutoResize(_ height: Any?) {
if let strHeight = height as? String,
let doubleHeight = Double(strHeight) {
if doubleHeight <= 0 {
Log.debug(label: self.LOG_PREFIX, "Invalid height value received for auto-resize: \(doubleHeight). Height must be positive.")
return
}
fitToContentHeight = CGFloat(doubleHeight)
// when enabled, this method isn't called until the html is loaded, requiring a redraw with the correct height
reframeMessage()
} else {
Log.debug(label: self.LOG_PREFIX, "Failed to parse height value for auto-resize: \(String(describing: height))")
}
}|
|
||
| // set the callback for auto-resizing if fitToContent is set in MessageSettings | ||
| if let fitToContent = self.settings?.fitToContent, | ||
| fitToContent, |
There was a problem hiding this comment.
Since the fitToContent value is not actually used inside the conditional block, what do you think of simplifying the logic a bit and making the intent more directly clear by using a direct Bool comparison to true instead?:
if self.settings?.fitToContent == true,
self.scriptHandlers[FIT_TO_CONTENT_HANDLER_NAME] == nil {
self.scriptHandlers[FIT_TO_CONTENT_HANDLER_NAME] = handleAutoResize(_:)
}
Description
[weak self]in dispatch async calls to prevent leakingTests will be coming in a future PR.
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: