Block utils
This document outlines the utility functions and extensions provided by the NativeblocksFoundation package to simplify working with SwiftUI blocks.
Extensions on String
Methods
isValidImageUrl()
Checks if the string is a valid URL for an image.
func isValidImageUrl() -> Bool
Returns
true if the URL is valid, otherwise false.
Extensions on View
Methods
blockWidthAndHeightModifier(::alignment:)
Applies a width and height modifier to a view.
func blockWidthAndHeightModifier(_ width: String, _ height: String, alignment: Alignment = .center) -> some View
Parameters
- width: The width string (e.g., "fill" or a numeric value).
- height: The height string (e.g., "fill" or a numeric value).
- alignment: The alignment for the view's frame.
Returns
A view with the specified frame settings.
blockFont(family:size:weight:design:)
func blockFont(family: String, size: CGFloat, weight: Font.Weight, design: Font.Design) -> some View
blockKeyboardType(_:)
Sets the keyboard type for text input fields within the view's environment.
func blockKeyboardType(_ type: String) -> some View
Supported keyboard types:
-
"asciicapable"
-
"numbersandpunctuation"
-
"url"
-
"numberpad"
-
"phonepad"
-
"namephonepad"
-
"emailaddress"
-
"decimalpad"
-
"twitter"
-
"websearch"
-
"asciicapablenumberpad"
-
"alphabet"
Defaults to .default if an unsupported type is provided.
Parameters
- type: A string representing the keyboard type (e.g., "asciicapable", "numberpad").
Returns
A view with the specified keyboard type applied.
blockAutocapitalization(_:)
Configures autocapitalization behavior for text input fields within the view's environment.
func blockAutocapitalization(_ type: String) -> some View
Supported autocapitalization types:
-
"allcharacters"
-
"sentences"
-
"words"
Defaults to .none if an unsupported type is provided.
Parameters
- type: A string representing the autocapitalization type (e.g., "allcharacters", "sentences", "words").
Returns
A view with the specified autocapitalization type applied.
blockScrollIndicators(_:)
Configures the visibility of scroll indicators within the view's environment.
func blockScrollIndicators(_ type: String) -> some View
Supported visibility options:
-
"automatic"
-
"hidden"
-
"never"
-
"visible"
Defaults to .visible if an unsupported type is provided. This feature is available on iOS 16.0 and later.
Parameters
- type: A string representing the scroll indicator visibility (e.g., "automatic", "hidden", "never", "visible").
Returns
A view with the specified scroll indicator visibility applied.
blockOnTapGesture(enable:_:)
func blockOnTapGesture(enable: Bool = true, _ action: @escaping () -> Void) -> some View
blockScaled(_:)
Scales the view based on the specified scaling mode.
func blockScaled(_ scale: String) -> some View
Parameters
- scale: The scaling mode as a string (e.g., "fill", "fit").
Returns
A view scaled according to the specified mode.
blockAspectRatio(ratio:mode:)
Sets the aspect ratio of the view based on a given ratio and mode.
func blockAspectRatio(ratio: CGFloat, mode: String) -> some View
Parameters
- ratio: The aspect ratio as a CGFloat.
- mode: The content mode as a string (e.g., "fill").
Returns
A view with the specified aspect ratio and mode applied.
Extensions on KFImage
Methods
blockResizable(_:)
Makes the image resizable based on the specified resizing mode.
func blockResizable(_ mode: String) -> KFImage
Parameters
- mode: The resizing mode as a string (e.g., "stretch", "tile").
Returns
A KFImage object configured with the specified resizing mode.
blockInterpolation(_:)
Configures the image interpolation quality.
func blockInterpolation(_ value: String) -> KFImage
Parameters
- value: The interpolation quality as a string (e.g., "high", "medium", "low").
Returns
A KFImage object with the specified interpolation setting.