### Build and Test Texture Locally Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/development/how-to-develop.md Build the Texture framework locally and ensure all tests pass. This script verifies your setup and checks for compatibility with required tool versions. Make sure you have the correct Xcode, Cocoapods, and Carthage versions installed. ```bash ./build.sh all ``` -------------------------------- ### Import Texture Framework Header (Objective-C) Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/installation.md This snippet shows how to import the main framework header for Texture in Objective-C projects. This is a prerequisite for using Texture's functionalities. ```objc #import ``` -------------------------------- ### Basic ASImageNode Initialization and Setup (Swift, Objective-C) Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/image-node.md Demonstrates the fundamental setup of an ASImageNode, similar to UIImageView. It covers initializing the node and setting the image and content mode. This is the most basic usage for displaying an image. ```swift let imageNode = ASImageNode() imageNode.image = UIImage(named: "someImage") imageNode.contentMode = .scaleAspectFill ``` ```objective-c ASImageNode *imageNode = [[ASImageNode alloc] init]; imageNode.image = [UIImage imageNamed:@"someImage"]; imageNode.contentMode = UIViewContentModeScaleAspectFill; ``` -------------------------------- ### Install Dependencies with CocoaPods Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/development/how-to-develop.md Install the necessary dependencies for the Texture framework using CocoaPods. After cloning the repository, navigate to the cloned directory and run this command. This will generate an Xcode workspace file. ```bash pod install ``` -------------------------------- ### Install Bundler and Run Jekyll Dependencies Source: https://github.com/texturegroup/texture/blob/master/docs/README.md Commands to install the Bundler gem, navigate to the project directory, and install Jekyll dependencies using Bundler. These steps are crucial for setting up a local Jekyll development environment. ```shell $ gem install bundler $ cd gh-pages # Go to folder $ bundle install # Might need sudo. ``` -------------------------------- ### Add Texture Dependency with Carthage (Latest Release) Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/installation.md This snippet demonstrates how to add Texture to your project's Cartfile to use the latest release branch via Carthage. It also includes the command to update dependencies. ```shell github "texturegroup/texture" ``` ```shell > carthage update ``` -------------------------------- ### Add Texture Dependency with Carthage (Master Branch) Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/installation.md This snippet shows how to specify the master branch of Texture in your Cartfile for Carthage integration. It includes the command to update dependencies. ```shell github "texturegroup/texture" "master" ``` ```shell > carthage update ``` -------------------------------- ### Install Texture with CocoaPods Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/installation.md Instructions for adding Texture as a dependency to your project using CocoaPods. This involves modifying your Podfile and running the 'pod install' command. ```objc target 'MyApp' do pod "Texture" end ``` ```shell > pod install ``` ```shell > pod update Texture ``` -------------------------------- ### NSSpain Talk Example Layout - Objective-C Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/automatic-layout-examples.md Demonstrates a vertical stack layout containing a title and body, within a horizontal stack that also includes an image. This is then inset. Uses ASStackLayoutSpec and ASInsetLayoutSpec. ```objective-c - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constraint { ASStackLayoutSpec *vStack = [[ASStackLayoutSpec alloc] init]; [vStack setChildren:@[titleNode, bodyNode]; ASStackLayoutSpec *hstack = [[ASStackLayoutSpec alloc] init]; hStack.direction = ASStackLayoutDirectionHorizontal; hStack.spacing = 5.0; [hStack setChildren:@[imageNode, vStack]]; ASInsetLayoutSpec *insetSpec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(5,5,5,5) child:hStack]; return insetSpec; } ``` -------------------------------- ### Overlay Photo with Outset Icon (Swift & Objective-C) Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/automatic-layout-examples-2.md This example shows how to place an icon in the corner of a photo using ASCornerLayoutSpec. It defines preferred sizes for both the photo and the icon, then positions the icon at the top-right corner of the photo. ```swift override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec { iconNode.style.preferredSize = CGSize(width: 40, height: 40) photoNode.style.preferredSize = CGSize(width: 150, height: 150) return ASCornerLayoutSpec(child: photoNode, corner: iconNode, location: .topRight) } ``` ```objective-c - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize { _iconNode.style.preferredSize = CGSizeMake(40, 40); _photoNode.style.preferredSize = CGSizeMake(150, 150); return [ASCornerLayoutSpec cornerLayoutSpecWithChild:_photoNode corner:_iconNode location:ASCornerLayoutLocationTopRight]; } ``` -------------------------------- ### Initialize ASDKViewController Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/subclassing.md Initializes an ASDKViewController with a node. Best practice is to create the node before calling super. Avoid accessing self.view or self.node.view in the initializer. ```objective-c - (instancetype)init { _pagerNode = [[ASPagerNode alloc] init]; self = [super initWithNode:_pagerNode]; // setup any instance variables or properties here if (self) { _pagerNode.dataSource = self; _pagerNode.delegate = self; } return self; } ``` ```swift init() { let pagerNode = ASPagerNode() super.init(node: pagerNode) pagerNode.setDataSource(self) pagerNode.setDelegate(self) } ``` -------------------------------- ### Clone Texture Repository Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/development/how-to-develop.md Clone the Texture framework's source code from GitHub. You can use either the SSH or HTTPS clone URL. This is the first step in setting up your local development environment. ```bash git clone git@github.com:TextureGroup/Texture.git ``` ```bash git clone https://github.com/TextureGroup/Texture.git ``` -------------------------------- ### Initial Video Loading Start Notification Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Protocols/ASVideoNodeDelegate.html Delegate method invoked when the video player begins loading the initial asset. This method is part of the ASVideoNodeDelegate protocol. ```objective-c - (void)videoNodeDidStartInitialLoading:(ASVideoNode *)_videoNode_ ``` -------------------------------- ### Social App Layout 2 - Objective-C Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/automatic-layout-examples.md Demonstrates a layout with an image overlaid by a 'sold out' label, combined with a text specification. These are then stacked vertically and an additional overlay is applied. Uses ASOverlayLayoutSpec and ASStackLayoutSpec. ```objective-c - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize { ASLayoutSpec *textSpec = [self textSpec]; ASLayoutSpec *imageSpec = [self imageSpecWithSize:constrainedSize]; ASOverlayLayoutSpec *soldOutOverImage = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:imageSpec overlay:[self soldOutLabelSpec]]; NSArray *stackChildren = @[soldOutOverImage, textSpec]; ASStackLayoutSpec *mainStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:0.0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStretch children:stackChildren]; ASOverlayLayoutSpec *soldOutOverlay = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:mainStack overlay:self.soldOutOverlay]; return soldOutOverlay; } - (ASLayoutSpec *)textSpec { CGFloat kInsetHorizontal = 16.0; CGFloat kInsetTop = 6.0; CGFloat kInsetBottom = 0.0; ``` -------------------------------- ### Initialize ASCellNode with ASDKViewController in Swift and Objective-C Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/containers-aspagernode.md This pattern demonstrates how to initialize an ASCellNode using an ASDKViewController for optimal performance. It's crucial to set the style.preferredSize for correct layout. This example shows the implementation in both Swift and Objective-C. ```objective-c - (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index { NSArray *animals = self.animals[index]; ASCellNode *node = [[ASCellNode alloc] initWithViewControllerBlock:^{ return [[AnimalTableNodeController alloc] initWithAnimals:animals];; } didLoadBlock:nil]; node.style.preferredSize = pagerNode.bounds.size; return node; } ``` ```swift func pagerNode(_ pagerNode: ASPagerNode, nodeAt index: Int) -> ASCellNode { guard animals.count > index else { return ASCellNode() } let animal = animals[index] let node = ASCellNode(viewControllerBlock: { () -> UIViewController in return AnimalTableNodeController(animals: animals) }, didLoadBlock: nil) node.style.preferredSize = pagerNode.bounds.size return node } ``` -------------------------------- ### Get Delegate for ASTextNode Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASTextNode.html A weak reference to the delegate object responsible for responding to actions from links within the text node. The delegate must implement specific methods for gesture recognizers to be installed. ```Objective-C @property (nonatomic, weak) id delegate ``` -------------------------------- ### Basic ASEditableTextNode Initialization and Text Setting Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/editable-text-node.md Initializes an ASEditableTextNode and sets its attributed text and text container inset. This is the fundamental setup for using the node as a text input field. It requires no external dependencies beyond the framework itself. ```objc ASEditableTextNode *editableTextNode = [[ASEditableTextNode alloc] init]; editableTextNode.attributedText = [[NSAttributedString alloc] initWithString:@"Lorem ipsum dolor sit amet."]; editableTextNode.textContainerInset = UIEdgeInsetsMake(8, 8, 8, 8); ``` ```swift let editableTextNode = ASEditableTextNode() editableTextNode.attributedText = NSAttributedString(string: "Lorem ipsum dolor sit amet.") editableTextNode.textContainerInset = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8) ``` -------------------------------- ### Serve Jekyll Website Locally Source: https://github.com/texturegroup/texture/blob/master/docs/README.md Instructions for running the Jekyll development server to preview the website locally. It also includes the command to open the default local URL in a web browser. ```shell $ bundle exec jekyll serve [--incremental] $ open http://localhost:4000/ ``` -------------------------------- ### Initialize ASVideoNode with AVAsset (Swift, Objective-C) Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/video-node.md Demonstrates how to create an ASVideoNode and assign an AVAsset to it for video playback. Requires linking AVFoundation. Accepts a URL string for the video asset. ```swift let videoNode = ASVideoNode() let asset = AVAsset(url: URL(string: "http://www.w3schools.com/html/mov_bbb.mp4")!) videoNode.asset = asset ``` ```objective-c ASVideoNode *videoNode = [[ASVideoNode alloc] init]; AVAsset *asset = [AVAsset assetWithURL:[NSURL URLWithString:@"http://www.w3schools.com/html/mov_bbb.mp4"]]; videoNode.asset = asset; ``` -------------------------------- ### Get Initial Frame for Node (Objective-C) Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Protocols/ASContextTransitioning.html Retrieves the frame of a given node as it was before the transition started. This method, part of the ASContextTransitioning protocol, returns CGRectNull if the node was not present initially. ```Objective-C - (CGRect)initialFrameForNode:(ASDisplayNode *)_node_ ``` -------------------------------- ### Initialize and Configure ASDisplayNode Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/display-node.md Demonstrates the initialization of an ASDisplayNode and setting basic properties like background color and bounds. It shows how to access the underlying UIView. ```objc ASDisplayNode *node = [[ASDisplayNode alloc] init]; node.backgroundColor = [UIColor orangeColor]; node.bounds = CGRectMake(0, 0, 100, 100); NSLog(@"Underlying view: %@", node.view); ``` ```swift let node = ASDisplayNode() node.backgroundColor = .orange node.bounds = CGRect(x: 0, y: 0, width: 100, height: 100) print("Underlying view: (node.view)") ``` -------------------------------- ### Debugging Layout Style Properties in LLDB Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/layout2-quickstart.md Illustrates how to inspect the style properties of a layout element using the LLDB debugger. This is useful for understanding and debugging sizing and layout constraints by printing the style object of an `ASLayoutElement`. ```objc (lldb) po _photoImageNode.style Layout Size = min {414pt, 414pt} <= preferred {20%, 50%} <= max {414pt, 414pt} ``` -------------------------------- ### Create Image Layout with Ratio and Overlay Specs Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/automatic-layout-examples.md This snippet demonstrates creating an image layout with a specified aspect ratio and overlaying a badge. It uses ASRatioLayoutSpec for aspect ratio fitting and ASOverlayLayoutSpec to place the badge on top of the image. The badge's position and size are explicitly set. ```objective-c - (ASLayoutSpec *)imageSpecWithSize:(ASSizeRange)constrainedSize { CGFloat imageRatio = [self imageRatioFromSize:constrainedSize.max]; ASRatioLayoutSpec *imagePlace = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:imageRatio child:self.dealImageView]; self.badge.layoutPosition = CGPointMake(0, constrainedSize.max.height - kFixedLabelsAreaHeight - kBadgeHeight); self.badge.sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(0), ASRelativeDimensionMakeWithPoints(kBadgeHeight)), ASRelativeSizeRangeMake(ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(1), ASRelativeDimensionMakeWithPoints(kBadgeHeight)))); ASStaticLayoutSpec *badgePosition = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[self.badge]]; ASOverlayLayoutSpec *badgeOverImage = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:imagePlace overlay:badgePosition]; badgeOverImage.flexGrow = YES; return badgeOverImage; } ``` -------------------------------- ### ASTableNode Tuning Parameters Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASTableNode.html Methods for getting and setting tuning parameters for range types and modes. ```APIDOC ## - tuningParametersForRangeType: ### Description Tuning parameters for a range type in full mode. ### Method - (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)_rangeType_ ### Parameters #### rangeType - **rangeType** (ASLayoutRangeType) - The range type to get the tuning parameters for. ### Return Value A tuning parameter value for the given range type in full mode. ### Declared In ASTableNode.h ## - setTuningParameters:forRangeType: ### Description Set the tuning parameters for a range type in full mode. ### Method - (void)setTuningParameters:(ASRangeTuningParameters)_tuningParameters_ forRangeType:(ASLayoutRangeType)_rangeType_ ### Parameters - **tuningParameters** (ASRangeTuningParameters) - The tuning parameters to store for a range type. - **rangeType** (ASLayoutRangeType) - The range type to set the tuning parameters for. ### Declared In ASTableNode.h ## - tuningParametersForRangeMode:rangeType: ### Description Tuning parameters for a range type in the specified mode. ### Method - (ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)_rangeMode_ rangeType:(ASLayoutRangeType)_rangeType_ ### Parameters - **rangeMode** (ASLayoutRangeMode) - The range mode to get the running parameters for. - **rangeType** (ASLayoutRangeType) - The range type to get the tuning parameters for. ### Return Value A tuning parameter value for the given range type in the given mode. ### Declared In ASTableNode.h ## - setTuningParameters:forRangeMode:rangeType: ### Description Set the tuning parameters for a range type in the specified mode. ### Method - (void)setTuningParameters:(ASRangeTuningParameters)_tuningParameters_ forRangeMode:(ASLayoutRangeMode)_rangeMode_ rangeType:(ASLayoutRangeType)_rangeType_ ### Parameters - **tuningParameters** (ASRangeTuningParameters) - The tuning parameters to store for a range type. - **rangeMode** (ASLayoutRangeMode) - The range mode to set the running parameters for. - **rangeType** (ASLayoutRangeType) - The range type to set the tuning parameters for. ### Declared In ASTableNode.h ``` -------------------------------- ### Create and Configure ASDisplayNode Source: https://context7.com/texturegroup/texture/llms.txt Demonstrates the basic creation and configuration of an ASDisplayNode, including setting background color, corner radius, shadow properties, and preferred size. It also shows how to add the node to a parent and access its underlying UIView on the main thread. ```objectivec ASDisplayNode *node = [[ASDisplayNode alloc] init]; node.backgroundColor = [UIColor blueColor]; node.cornerRadius = 8.0; node.shadowColor = [[UIColor blackColor] CGColor]; node.shadowOpacity = 0.3; // Configure layout with style properties node.style.preferredSize = CGSizeMake(100, 100); node.style.flexGrow = 1.0; // Add to hierarchy (can be done on background thread) [parentNode addSubnode:node]; // Access the underlying view (must be on main thread) dispatch_async(dispatch_get_main_queue(), ^{ UIView *view = node.view; [self.view addSubview:view]; }); ``` -------------------------------- ### GET /texturegroup/texture/indexPathForNode Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASCollectionNode.html Retrieves the index path for an item given its node. This is the inverse operation of `nodeForItemAtIndexPath:`. ```APIDOC ## GET /texturegroup/texture/indexPathForNode ### Description Retrieve the index path for the item with the given node. ### Method GET ### Endpoint `/texturegroup/texture/indexPathForNode` ### Parameters #### Query Parameters - **cellNode** (ASCellNode) - Required - A node for an item in the collection node. ### Response #### Success Response (200) - **indexPath** (NSIndexPath) - The index path for this item. #### Response Example { "indexPath": { "section": 0, "item": 0 } } ``` -------------------------------- ### Initialize ASDisplayNode with a Custom View Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/display-node.md Illustrates how to initialize an ASDisplayNode by providing a block that returns a custom UIView to be used as its backing view. This is useful for wrapping existing views. ```objc ASDisplayNode *node = [ASDisplayNode alloc] initWithViewBlock:^{ SomeView *view = [[SomeView alloc] init]; return view; }]; ``` ```swift let node = ASDisplayNode { () -> UIView in let view = SomeView() return view } ``` -------------------------------- ### Highlight Range Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASTextNode.html Sets or gets the specific range of text that should be highlighted. Changes are not animated by default. ```APIDOC ## GET /texturegroup/texture/highlightRange ### Description Gets the range of text highlighted by the receiver. ### Method GET ### Endpoint `/texturegroup/texture/highlightRange` ### Response #### Success Response (200) - **highlightRange** (NSRange) - The range of text currently highlighted. #### Response Example ```json { "highlightRange": { "location": 5, "length": 10 } } ``` ## PUT /texturegroup/texture/highlightRange ### Description Sets the range of text to highlight. ### Method PUT ### Endpoint `/texturegroup/texture/highlightRange` ### Parameters #### Request Body - **highlightRange** (NSRange) - Required - The range of text to highlight. - **animated** (BOOL) - Optional - Whether the text should be highlighted with an animation. Defaults to false. ### Request Example ```json { "highlightRange": { "location": 15, "length": 8 }, "animated": true } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Highlight range updated successfully." } ``` ``` -------------------------------- ### ASMultiplexImageNode Initialization Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASMultiplexImageNode.html Initializes an ASMultiplexImageNode with a cache and downloader. ```APIDOC ## initWithCache:downloader: ### Description The designated initializer for ASMultiplexImageNode. ### Method - (instancetype)initWithCache:(nullable id)_cache_ downloader:(nullable id)_downloader_ ### Parameters #### Path Parameters - `cache` (id) - The object that implements a cache of images for the image node. - `downloader` (id) - The object that implements image downloading for the image node. ### Response #### Success Response (200) - An initialized ASMultiplexImageNode. ### Discussion If `cache` is nil, the receiver will not attempt to retrieve images from a cache before downloading them. ``` -------------------------------- ### ASCollectionView Tuning Parameters Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Categories/ASCollectionView+Deprecated.html This section covers how to get and set tuning parameters for layout ranges in ASCollectionView. ```APIDOC ## ASCollectionView Tuning Parameters ### Description Retrieves or sets tuning parameters for layout ranges within an ASCollectionView. ### Method - `(ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType` ### Parameters #### Path Parameters - **rangeType** (ASLayoutRangeType) - Required - The type of layout range to get tuning parameters for. ### Return Value A tuning parameter value for the given range type in full mode. ### Method - `(void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType` ### Parameters #### Path Parameters - **tuningParameters** (ASRangeTuningParameters) - Required - The tuning parameters to store. - **rangeType** (ASLayoutRangeType) - Required - The type of layout range to set tuning parameters for. ### Method - `(ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType` ### Parameters #### Path Parameters - **rangeMode** (ASLayoutRangeMode) - Required - The range mode to get tuning parameters for. - **rangeType** (ASLayoutRangeType) - Required - The type of layout range to get tuning parameters for. ### Return Value A tuning parameter value for the given range type in the specified mode. ### Method - `(void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType` ### Parameters #### Path Parameters - **tuningParameters** (ASRangeTuningParameters) - Required - The tuning parameters to store. - **rangeMode** (ASLayoutRangeMode) - Required - The range mode to set tuning parameters for. - **rangeType** (ASLayoutRangeType) - Required - The type of layout range to set tuning parameters for. ``` -------------------------------- ### Get Number of Sections in ASCollectionNode Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASCollectionNode.html Provides the total number of sections available in the collection node. This is a read-only property. ```Objective-C @property (nonatomic, readonly) NSInteger numberOfSections ``` -------------------------------- ### ASNetworkImageNode Initializers Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASNetworkImageNode.html Provides methods for initializing ASNetworkImageNode instances, with options for custom cache and downloader objects or default configurations. ```APIDOC ## ASNetworkImageNode Initializers ### Description Initializes an ASNetworkImageNode instance. ### Method - `initWithCache:downloader:` - `init` ### Parameters #### `initWithCache:downloader:` - **cache** (id) - Weak reference. The cache object for the image node. - **downloader** (id) - Weak reference. The image downloader object (must not be nil). #### `init` No parameters. ### Return Value An initialized ASNetworkImageNode. ### Discussion - `initWithCache:downloader:`: If `cache` is nil, the receiver will not attempt to retrieve images from a cache before downloading. - `init`: Configures the node to use the default `ASBasicImageDownloader` and no extra cache. ### Declared In ASNetworkImageNode.h ``` -------------------------------- ### GET /texturegroup/texture/cellForItemAtIndexPath Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASCollectionNode.html Retrieves the UICollectionViewCell corresponding to the item at the specified index path. This method must be called on the main thread. ```APIDOC ## GET /texturegroup/texture/cellForItemAtIndexPath ### Description Retrieve the cell at the given index path. ### Method GET ### Endpoint `/texturegroup/texture/cellForItemAtIndexPath` ### Parameters #### Query Parameters - **indexPath** (NSIndexPath) - Required - The index path of the requested item. ### Response #### Success Response (200) - **cell** (UICollectionViewCell) - The cell for the given index path, or nil if the cell is not currently loaded or visible. #### Response Example { "cell": { "reuseIdentifier": "MyCellIdentifier" } } ``` -------------------------------- ### Get Highlight Range in ASTextNode Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASTextNode.html Specifies the range of text that is currently highlighted by the receiver. Changes to this property are not animated by default. ```Objective-C @property (nonatomic, assign) NSRange highlightRange ``` -------------------------------- ### Create Basic ASTextNode (Swift, Objective-C) Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/text-node.md Demonstrates how to create a basic ASTextNode by initializing it and setting an attributed string for the text content. This is the fundamental step for displaying text with ASTextNode. ```swift let attrs = [NSFontAttributeName: UIFont(name: "HelveticaNeue", size: 12.0)] let string = NSAttributedString(string: "Hey, here's some text.", attributes: attrs) node = ASTextNode() node.attributedText = string ``` ```objective-c NSDictionary *attrs = @{ NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:12.0f] }; NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"Hey, here's some text." attributes:attrs]; _node = [[ASTextNode alloc] init]; _node.attributedText = string; ``` -------------------------------- ### ASTableNode Initialization Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASTableNode.html Details on how to initialize an ASTableNode instance. ```APIDOC ## - init ### Description Designated initializer. ### Method - (instancetype)init ### Return Value An ASDisplayNode instance whose view will be a subclass that enables asynchronous rendering, and passes through -layout and touch handling methods. ### Declared In ASTableNode.h ``` -------------------------------- ### Get Background Image Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASButtonNode.html Retrieves the background image associated with a given control state. ```APIDOC ## GET /texturegroup/texture/backgroundImage ### Description Returns the background image used for a button state. ### Method GET ### Endpoint /texturegroup/texture/backgroundImage ### Parameters #### Query Parameters - **state** (ASControlState) - Required - The state that uses the image. Possible values are described in ASControlState. ### Request Example ```json { "state": "UIControlStateHighlighted" } ``` ### Response #### Success Response (200) - **backgroundImage** (UIImage) - The background image used for the specified state. #### Response Example ```json { "backgroundImage": "UIImage object" } ``` ``` -------------------------------- ### GET /texturegroup/texture/nodeForItemAtIndexPath Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASCollectionNode.html Retrieves the node for the item at the specified index path. This method is useful for accessing the visual representation of an item in the collection. ```APIDOC ## GET /texturegroup/texture/nodeForItemAtIndexPath ### Description Retrieves the node for the item at the given index path. ### Method GET ### Endpoint `/texturegroup/texture/nodeForItemAtIndexPath` ### Parameters #### Query Parameters - **indexPath** (NSIndexPath) - Required - The index path of the requested item. ### Response #### Success Response (200) - **node** (ASCellNode) - The node for the given item, or nil if no item exists at the specified path. #### Response Example { "node": { "kindof": "ASCellNode" } } ``` -------------------------------- ### ASTableNode: Implement Performant Table Views Source: https://context7.com/texturegroup/texture/llms.txt This snippet illustrates the setup and usage of ASTableNode for creating efficient table views. It details initialization, configuration for batch fetching (infinite scrolling), inverted layout for chat interfaces, and range tuning for performance. Data source and delegate methods, including asynchronous cell node creation and batch updates, are also presented. ```objective-c // Initialize table node ASTableNode *tableNode = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain]; tableNode.delegate = self; tableNode.dataSource = self; // Configure batch fetching (infinite scroll) tableNode.leadingScreensForBatching = 2.0; // Trigger 2 screens before end // Configure for chat/messaging (inverted) tableNode.inverted = YES; // Range tuning for performance optimization ASRangeTuningParameters preloadParams = { .leadingBufferScreenfuls = 2.0, .trailingBufferScreenfuls = 1.0 }; [tableNode setTuningParameters:preloadParams forRangeType:ASLayoutRangeTypePreload]; // Data source - provide nodes via blocks (preferred) - (NSInteger)numberOfSectionsInTableNode:(ASTableNode *)tableNode { return self.sections.count; } - (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section { return [self.sections[section] count]; } - (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath { MyDataItem *item = [self itemAtIndexPath:indexPath]; // Return block that creates node (called on background thread) return ^ASCellNode *{ MyCellNode *cell = [[MyCellNode alloc] initWithItem:item]; return cell; }; } // Delegate methods - (void)tableNode:(ASTableNode *)tableNode didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableNode deselectRowAtIndexPath:indexPath animated:YES]; [self handleSelection:indexPath]; } - (void)tableNode:(ASTableNode *)tableNode willBeginBatchFetchWithContext:(ASBatchContext *)context { [self loadMoreDataWithCompletion:^(NSArray *newItems) { [self insertNewItems:newItems]; [context completeBatchFetching:YES]; }]; } // Batch updates [tableNode performBatchUpdates:^{ [tableNode insertRowsAtIndexPaths:newIndexPaths withRowAnimation:UITableViewRowAnimationFade]; [tableNode deleteRowsAtIndexPaths:oldIndexPaths withRowAnimation:UITableViewRowAnimationFade]; } completion:^(BOOL finished) { NSLog(@"Updates complete"); }]; // Reload data [tableNode reloadDataWithCompletion:^{ NSLog(@"Reload complete"); }]; ``` -------------------------------- ### Get Number of Items in Section in ASCollectionNode Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASCollectionNode.html Returns the total number of items present within a specified section of the collection node. ```Objective-C - (NSInteger)numberOfItemsInSection:(NSInteger)_section_ ``` -------------------------------- ### Get Link Attribute Names in ASTextNode Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASTextNode.html Returns the set of attribute names that are considered links. By default, this property includes NSLinkAttributeName. ```Objective-C @property (nonatomic, copy) NSArray *linkAttributeNames ``` -------------------------------- ### Initialize ASMultiplexImageNode in Objective-C and Swift Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/multiplex-image-node.md Initializes an ASMultiplexImageNode with a dictionary of image URLs. It configures the node to download intermediate images and sets the order of image quality identifiers. The data source and delegate are also assigned. ```objective-c - (instancetype)initWithURLs:(NSDictionary *)urls { ... _imageURLs = urls; // something like @{@"thumb": "/smallImageUrl", @"medium": ...} _multiplexImageNode = [[ASMultiplexImageNode alloc] initWithCache:nil downloader:[ASBasicImageDownloader sharedImageDownloader]]; _multiplexImageNode.downloadsIntermediateImages = YES; _multiplexImageNode.imageIdentifiers = @[ @"original", @"medium", @"thumb" ]; _multiplexImageNode.dataSource = self; _multiplexImageNode.delegate = self; ... } ``` ```swift init(urls: [String:NSURL]) { imageURLs = urls multiplexImageNode = ASMultiplexImageNode(cache: nil, downloader: ASBasicImageDownloader.shared()) multiplexImageNode.downloadsIntermediateImages = true multiplexImageNode.imageIdentifiers = ["original", "medium", "thumb" ] multiplexImageNode.dataSource = self multiplexImageNode.delegate = self ... } ``` -------------------------------- ### GET /texturegroup/texture/eventLog Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Categories/ASDisplayNode+Beta.html Retrieves the most recent trace events for a texture node. The maximum count is ASDISPLAYNODE_EVENTLOG_CAPACITY. ```APIDOC ## GET /texturegroup/texture/eventLog ### Description Retrieves an array containing the most recent trace events logged for this texture node. The maximum number of events stored is defined by ASDISPLAYNODE_EVENTLOG_CAPACITY. ### Method GET ### Endpoint /texturegroup/texture/eventLog ### Parameters No parameters are required for this endpoint. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **eventLog** (array) - An array of strings, where each string represents a logged event. #### Response Example ```json { "eventLog": [ "Event 1: Texture loaded", "Event 2: Texture displayed", "Event 3: Memory warning handled" ] } ``` ``` -------------------------------- ### ASButtonNode: Create and Configure Interactive Buttons Source: https://context7.com/texturegroup/texture/llms.txt This snippet demonstrates how to initialize and configure an ASButtonNode. It covers setting titles, attributed strings, images, and background images for different control states. Layout, alignment, and tap handling are also shown. This node supports asynchronous rendering for improved performance. ```objective-c ASButtonNode *buttonNode = [[ASButtonNode alloc] init]; // Set titles for different states [buttonNode setTitle:@"Tap Me" withFont:[UIFont boldSystemFontOfSize:16] withColor:[UIColor whiteColor] forState:UIControlStateNormal]; [buttonNode setTitle:@"Loading..." withFont:[UIFont boldSystemFontOfSize:16] withColor:[UIColor lightGrayColor] forState:UIControlStateDisabled]; // Or use attributed strings for more control NSDictionary *attrs = @{NSFontAttributeName: [UIFont systemFontOfSize:16]}; NSAttributedString *title = [[NSAttributedString alloc] initWithString:@"Submit" attributes:attrs]; [buttonNode setAttributedTitle:title forState:UIControlStateNormal]; // Set images and background images [buttonNode setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal]; [buttonNode setBackgroundImage:[UIImage imageNamed:@"button_bg.png"] forState:UIControlStateNormal]; // Configure layout buttonNode.contentSpacing = 8.0; // Space between image and text buttonNode.laysOutHorizontally = YES; // Horizontal vs vertical layout buttonNode.imageAlignment = ASButtonNodeImageAlignmentBeginning; buttonNode.contentHorizontalAlignment = ASHorizontalAlignmentMiddle; buttonNode.contentVerticalAlignment = ASVerticalAlignmentCenter; buttonNode.contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20); // Handle taps [buttonNode addTarget:self action:@selector(buttonTapped:) forControlEvents:ASControlNodeEventTouchUpInside]; - (void)buttonTapped:(ASButtonNode *)sender { sender.enabled = NO; [self performAsyncOperation:^{ sender.enabled = YES; }]; } ``` -------------------------------- ### ASTableNode: Get Visible Nodes Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASTableNode.html Returns an array of ASCellNode objects currently visible on the screen. This method must be called on the main thread. ```Objective-C @property (nonatomic, readonly) NSArray<__kindof ASCellNode*> *visibleNodes ``` -------------------------------- ### GET /texturegroup/texture/contextForSection Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASCollectionNode.html Retrieves the context object for a given section, as provided by the data source. This context can be used for section-specific configurations or data access. ```APIDOC ## GET /texturegroup/texture/contextForSection ### Description Retrieves the context object for the given section, as provided by the data source in the @c collectionNode:contextForSection: method. ### Method GET ### Endpoint `/texturegroup/texture/contextForSection` ### Parameters #### Query Parameters - **section** (NSInteger) - Required - The section index to get the context for. ### Response #### Success Response (200) - **context** (id) - The context object for the section, or nil if no context was provided by the data source. #### Response Example { "context": { "sectionIdentifier": "uniqueSectionId" } } ``` -------------------------------- ### GET /texturegroup/texture/indexPathsForVisibleItems Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASCollectionNode.html Returns an array containing the index paths of all currently visible items in the collection node. This must be called on the main thread. ```APIDOC ## GET /texturegroup/texture/indexPathsForVisibleItems ### Description Retrieve the index paths of all visible items. ### Method GET ### Endpoint `/texturegroup/texture/indexPathsForVisibleItems` ### Parameters None ### Response #### Success Response (200) - **indexPaths** (NSArray) - An array containing the index paths of all visible items. #### Response Example { "indexPaths": [ { "section": 0, "item": 0 }, { "section": 0, "item": 1 } ] } ``` -------------------------------- ### ASVideoNodeDelegate Methods Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Protocols/ASVideoNodeDelegate.html Methods for handling various events related to the ASVideoNode, such as video playback completion, taps, player state changes, loading progress, and stalls. ```APIDOC ## ASVideoNodeDelegate Protocol Reference Conforms to [ASNetworkImageNodeDelegate](../Protocols/ASNetworkImageNodeDelegate.html) Declared in ASVideoNode.h ### `videoDidPlayToEnd:` Delegate method invoked when the node’s video has played to its end time. - (void)videoDidPlayToEnd:(ASVideoNode *)_videoNode_ #### Parameters - **videoNode** (ASVideoNode *) - The video node has played to its end time. ### `didTapVideoNode:` Delegate method invoked the node is tapped. - (void)didTapVideoNode:(ASVideoNode *)_videoNode_ #### Parameters - **videoNode** (ASVideoNode *) - The video node that was tapped. #### Discussion The video’s play state is toggled if this method is not implemented. ### `videoNode:willChangePlayerState:toState:` Delegate method invoked when player changes state. - (void)videoNode:(ASVideoNode *)_videoNode_ willChangePlayerState:(ASVideoNodePlayerState)_state_ toState:(ASVideoNodePlayerState)_toState_ #### Parameters - **videoNode** (ASVideoNode *) - The video node. - **state** (ASVideoNodePlayerState) - player state before this change. - **toState** (ASVideoNodePlayerState) - player new state. #### Discussion This method is called after each state change ### `videoNode:shouldChangePlayerStateTo:` Asks delegate if state change is allowed ASVideoNodePlayerStatePlaying or ASVideoNodePlayerStatePaused. - (BOOL)videoNode:(ASVideoNode *)_videoNode_ shouldChangePlayerStateTo:(ASVideoNodePlayerState)_state_ #### Parameters - **videoNode** (ASVideoNode *) - The video node. - **state** (ASVideoNodePlayerState) - player state that is going to be set. #### Discussion Delegate method invoked when player changes it’s state to ASVideoNodePlayerStatePlaying or ASVideoNodePlayerStatePaused and asks delegate if state change is valid ### `videoNode:didPlayToTimeInterval:` Delegate method invoked when player playback time is updated. - (void)videoNode:(ASVideoNode *)_videoNode_ didPlayToTimeInterval:(NSTimeInterval)_timeInterval_ #### Parameters - **videoNode** (ASVideoNode *) - The video node. - **second** (NSTimeInterval) - current playback time in seconds. ### `videoNode:didStallAtTimeInterval:` Delegate method invoked when the video player stalls. - (void)videoNode:(ASVideoNode *)_videoNode_ didStallAtTimeInterval:(NSTimeInterval)_timeInterval_ #### Parameters - **videoNode** (ASVideoNode *) - The video node that has experienced the stall - **second** (NSTimeInterval) - Current playback time when the stall happens ### `videoNodeDidStartInitialLoading:` Delegate method invoked when the video player starts the initial asset loading. - (void)videoNodeDidStartInitialLoading:(ASVideoNode *)_videoNode_ #### Parameters - **videoNode** (ASVideoNode *) - The videoNode ### `videoNodeDidFinishInitialLoading:` Delegate method invoked when the video is done loading the asset and can start the playback. - (void)videoNodeDidFinishInitialLoading:(ASVideoNode *)_videoNode_ #### Parameters - **videoNode** (ASVideoNode *) - The videoNode ### `videoNode:didSetCurrentItem:` Delegate method invoked when the AVPlayerItem for the asset has been set up and can be accessed through currentItem. - (void)videoNode:(ASVideoNode *)_videoNode_ didSetCurrentItem:(AVPlayerItem *)_currentItem_ #### Parameters - **videoNode** (ASVideoNode *) - The videoNode. - **currentItem** (AVPlayerItem *) - The AVPlayerItem that was constructed from the asset. ### `videoNodeDidRecoverFromStall:` Delegate method invoked when the video node has recovered from the stall. - (void)videoNodeDidRecoverFromStall:(ASVideoNode *)_videoNode_ #### Parameters - **videoNode** (ASVideoNode *) - The videoNode ``` -------------------------------- ### Social App Layout - Objective-C Source: https://github.com/texturegroup/texture/blob/master/docs/_docs/automatic-layout-examples.md Constructs a social app layout including a header stack with user avatar, name, and time, followed by a photo. The header is inset and then placed in a vertical stack with the photo. Uses ASStackLayoutSpec and ASInsetLayoutSpec. ```objective-c - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize { // header stack _userAvatarImageView.preferredFrameSize = CGSizeMake(USER_IMAGE_HEIGHT, USER_IMAGE_HEIGHT); // constrain avatar image frame size ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init]; spacer.flexGrow = YES; ASStackLayoutSpec *headerStack = [ASStackLayoutSpec horizontalStackLayoutSpec]; headerStack.alignItems = ASStackLayoutAlignItemsCenter; // center items vertically in horizontal stack headerStack.justifyContent = ASStackLayoutJustifyContentStart; // justify content to left side of header stack headerStack.spacing = HORIZONTAL_BUFFER; [headerStack setChildren:@[_userAvatarImageView, _userNameLabel, spacer, _photoTimeIntervalSincePostLabel]]; // header inset stack UIEdgeInsets insets = UIEdgeInsetsMake(0, HORIZONTAL_BUFFER, 0, HORIZONTAL_BUFFER); ASInsetLayoutSpec *headerWithInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:headerStack]; headerWithInset.flexShrink = YES; // vertical stack CGFloat cellWidth = constrainedSize.max.width; _photoImageView.preferredFrameSize = CGSizeMake(cellWidth, cellWidth); // constrain photo frame size ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec verticalStackLayoutSpec]; verticalStack.alignItems = ASStackLayoutAlignItemsStretch; // stretch headerStack to fill horizontal space [verticalStack setChildren:@[headerWithInset, _photoImageView, footerWithInset]]; return verticalStack; } ``` -------------------------------- ### Trailing Rect Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASTextNode.html Gets the rectangle representing the trailing space after the final character in the text. Useful for determining available space or layout margins. ```APIDOC ## GET /texturegroup/texture/trailingRect ### Description Returns the trailing rectangle of space in the receiver, after the final character. ### Method GET ### Endpoint `/texturegroup/texture/trailingRect` ### Response #### Success Response (200) - **trailingRect** (CGRect) - A CGRect object representing the trailing space. #### Response Example ```json { "trailingRect": { "x": 110.0, "y": 10.0, "width": 20.0, "height": 20.0 } } ``` ``` -------------------------------- ### Get Visible Nodes in ASCollectionNode Source: https://github.com/texturegroup/texture/blob/master/docs/appledoc/Classes/ASCollectionNode.html Returns an array containing all the cell nodes currently visible on the screen. This property must be accessed on the main thread. ```Objective-C @property (nonatomic, readonly) NSArray<__kindofASCellNode*> *visibleNodes ```