Repository navigation
feat(view-shot): render options, image disposal and crash fixes - #25
Open
edusperoni wants to merge 3 commits into
Open
edusperoni wants to merge 3 commits into
edusperoni wants to merge 3 commits into
Conversation
- iOS: render with UIGraphicsImageRenderer instead of the deprecated UIGraphicsBeginImageContextWithOptions, which aborts the app on empty sizes or failed bitmap allocations - add RenderOptions (scale, opaque, range, bitmapConfig) to all render functions; defaults keep the previous output - renderToImageSource returns null for views without a native view or with an empty size instead of crashing - android: attach background views to the foreground activity and don't crash disposing an already detached view - add renderViewToImage, disposeImage and withRenderedImage - angular: forward RenderOptions and always dispose background and Angular views, even when rendering or the delay callback throws
|
View your CI Pipeline Execution ↗ for commit bedc9b5
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improvements to
@valor/nativescript-view-shotfrom profiling an app that snapshots offscreen views many times per second. Intended for a minor release.Crash fixes
UIGraphicsImageRendererinstead of the deprecated (iOS 17)UIGraphicsBeginImageContextWithOptions. The old API raises an uncatchableNSInternalInconsistencyExceptionon a 0×0 size or a failed bitmap allocation, and leaks its context if rendering throws. No version gate is needed: the renderer exists since iOS 10 andpreferredRangesince iOS 12.renderToImageSourcereturnsnullfor views with no native view or an empty size (typically a missingmeasureAndLayout) instead of crashing. On Android,Bitmap.createBitmap(0, …)used to throw.foregroundActivity ?? startActivityinstead of alwaysstartActivity.disposeBackgroundViewno longer throws when the view is already detached.captureInBackgrounddisposes the background views and destroys the Angular view infinally, so a throwingdelaycallback or render no longer leaks them.New API
RenderOptionson every render function:scale: pixels per DIP/point, defaults to the screen scale.opaque.range: iOS only,'standard'(default),'extended'or'automatic'.bitmapConfig: Android only,'ARGB_8888'(default) or'RGB_565'.renderViewToImage(view, { width, height, host, ...renderOptions }): load, measure, render and dispose in one call.withRenderedImage(view, callback, options): releases the native image (Utils.releaseNativeObject) when the callback returns, or when its promise settles. Rendered pixel memory is invisible to the JS GC, so discarded images otherwise pile up until an unrelated collection runs. The README documents callingUtils.releaseNativeObjectdirectly for manual release.ViewShotServiceforwardsRenderOptionsincaptureInBackgroundandcaptureRenderedView.Typing change
renderToImageSource,captureInBackgroundandcaptureRenderedViewnow returnImageSource | null.Strict mode
The package (core and Angular entry point) now compiles with
strict: true, so the shipped.d.tsfiles reflect real nullability. The only lib-check finding in strict consumers withskipLibCheck: falseis TS2611 onLogicalViewContainer'sios/androidgetters, which core's ownProxyViewContainerraises identically.Testing
nx run nativescript-view-shot:build.allandlintpass (lint now warning-free).RenderOptions,renderViewToImage,withRenderedImageand theImageSource | nullreturn types all resolve as expected.withRenderedImage/scale: 1.