Skip to content

[PLATIR-40656] Check for and execute auto-resize of IAM height, safer use of dispatch async#1122

Merged
sbenedicadb merged 4 commits intoadobe:dev-v5.4.1from
sbenedicadb:dev-v5.4.1
Apr 15, 2025
Merged

[PLATIR-40656] Check for and execute auto-resize of IAM height, safer use of dispatch async#1122
sbenedicadb merged 4 commits intoadobe:dev-v5.4.1from
sbenedicadb:dev-v5.4.1

Conversation

@sbenedicadb
Copy link
Copy Markdown
Member

@sbenedicadb sbenedicadb commented Apr 11, 2025

Description

  • calls a javascript method that may be present in in-app messages that can allow us to auto-resize the height to fit content
  • capture [weak self] in dispatch async calls to prevent leaking
  • ran the formatter (lots of whitespace in the diff)

Tests will be coming in a future PR.

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Copy Markdown
Contributor

@PravinPK PravinPK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we print a warning log here, just in case if handleAutoResize function fails to reframe message because of casting issues

Copy link
Copy Markdown
Contributor

@timkimadobe timkimadobe Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))")
    }
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good suggestions - i'll get this change in

}
]
},
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if it's a novice question- Is this file auto-generated ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I believe it's created using the make api-dump command within the repo

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Copy link
Copy Markdown
Contributor

@timkimadobe timkimadobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
}
Copy link
Copy Markdown
Contributor

@timkimadobe timkimadobe Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(_:)
}

@sbenedicadb sbenedicadb merged commit fa29e0a into adobe:dev-v5.4.1 Apr 15, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants