@@ -66,10 +66,10 @@ + (CALayer *)createBackgroundImageLayerWithSize:(const CGRect&)positioningArea
6666 auto widthOfEdgePinnedImages = itemSize.width * 2 ;
6767 auto availableWidthForCenterImages = paintingArea.size .width - widthOfEdgePinnedImages;
6868 if (availableWidthForCenterImages > 0 || floatEquality (availableWidthForCenterImages, 0.0 )) {
69- // Use pixel aligned values to avoid floating point precision issues
70- auto alignedAvailableWidth = [RCTBackgroundImageUtils pixelAlign: availableWidthForCenterImages] ;
71- auto alignedItemWidth = [RCTBackgroundImageUtils pixelAlign: itemSize.width] ;
72- auto centerImagesCount = floor (alignedAvailableWidth / alignedItemWidth );
69+ // Use rounded values to avoid floating point precision issues
70+ auto roundedAvailableWidth = round ( availableWidthForCenterImages) ;
71+ auto roundedItemWidth = round ( itemSize.width ) ;
72+ auto centerImagesCount = floor (roundedAvailableWidth / roundedItemWidth );
7373 auto centerImagesWidth = centerImagesCount * itemSize.width ;
7474 auto totalFreeSpace = availableWidthForCenterImages - centerImagesWidth;
7575 auto totalInstances = centerImagesCount + 2 ;
@@ -89,11 +89,11 @@ + (CALayer *)createBackgroundImageLayerWithSize:(const CGRect&)positioningArea
8989 replicatorX.instanceCount = 1 ;
9090 } else {
9191 replicatorX.instanceTransform = CATransform3DMakeTranslation (itemSize.width , 0 , 0 );
92- auto alignedGradientFrameX = [RCTBackgroundImageUtils pixelAlign: gradientFrameX] ;
93- auto alignedItemWidth = [RCTBackgroundImageUtils pixelAlign: itemSize.width] ;
94- auto alignedPaintingWidth = [RCTBackgroundImageUtils pixelAlign: paintingArea.size.width] ;
95- auto tilesBeforeX = ceil (alignedGradientFrameX / alignedItemWidth );
96- auto tilesAfterX = ceil ((alignedPaintingWidth - alignedGradientFrameX ) / alignedItemWidth );
92+ auto roundedGradientFrameX = round ( gradientFrameX) ;
93+ auto roundedItemWidth = round ( itemSize.width ) ;
94+ auto roundedPaintingWidth = round ( paintingArea.size .width ) ;
95+ auto tilesBeforeX = ceil (roundedGradientFrameX / roundedItemWidth );
96+ auto tilesAfterX = ceil ((roundedPaintingWidth - roundedGradientFrameX ) / roundedItemWidth );
9797 auto totalInstances = tilesBeforeX + tilesAfterX;
9898 replicatorX.instanceCount = totalInstances;
9999 finalX = gradientFrameX - (tilesBeforeX * itemSize.width );
@@ -118,10 +118,10 @@ + (CALayer *)createBackgroundImageLayerWithSize:(const CGRect&)positioningArea
118118 auto heightOfEdgePinnedImages = itemSize.height * 2 ;
119119 auto availableHeightForCenterImages = paintingArea.size .height - heightOfEdgePinnedImages;
120120 if (availableHeightForCenterImages > 0 || floatEquality (availableHeightForCenterImages, 0.0 )) {
121- // Use pixel aligned values to avoid floating point precision issues
122- auto alignedAvailableHeight = [RCTBackgroundImageUtils pixelAlign: availableHeightForCenterImages] ;
123- auto alignedItemHeight = [RCTBackgroundImageUtils pixelAlign: itemSize.height] ;
124- auto centerImagesCount = floor (alignedAvailableHeight / alignedItemHeight );
121+ // Use pixel rounded values to avoid floating point precision issues
122+ auto roundedAvailableHeight = round ( availableHeightForCenterImages) ;
123+ auto roundedItemHeight = round ( itemSize.height ) ;
124+ auto centerImagesCount = floor (roundedAvailableHeight / roundedItemHeight );
125125 auto centerImagesHeight = centerImagesCount * itemSize.height ;
126126 auto totalFreeSpace = availableHeightForCenterImages - centerImagesHeight;
127127 auto totalInstances = centerImagesCount + 2 ;
@@ -139,11 +139,11 @@ + (CALayer *)createBackgroundImageLayerWithSize:(const CGRect&)positioningArea
139139 replicatorY.instanceCount = 1 ;
140140 } else {
141141 replicatorY.instanceTransform = CATransform3DMakeTranslation (0 , itemSize.height , 0 );
142- auto alignedGradientFrameY = [RCTBackgroundImageUtils pixelAlign: gradientFrameY] ;
143- auto alignedItemHeight = [RCTBackgroundImageUtils pixelAlign: itemSize.height] ;
144- auto alignedPaintingHeight = [RCTBackgroundImageUtils pixelAlign: paintingArea.size.height] ;
145- auto tilesBeforeY = ceil (alignedGradientFrameY / alignedItemHeight );
146- auto tilesAfterY = ceil ((alignedPaintingHeight - alignedGradientFrameY ) / alignedItemHeight );
142+ auto roundedGradientFrameY = round ( gradientFrameY) ;
143+ auto roundedItemHeight = round ( itemSize.height ) ;
144+ auto roundedPaintingHeight = round ( paintingArea.size .height ) ;
145+ auto tilesBeforeY = ceil (roundedGradientFrameY / roundedItemHeight );
146+ auto tilesAfterY = ceil ((roundedPaintingHeight - roundedGradientFrameY ) / roundedItemHeight );
147147 auto instanceCount = tilesBeforeY + tilesAfterY;
148148 replicatorY.instanceCount = instanceCount;
149149 finalY = gradientFrameY - (tilesBeforeY * itemSize.height );
@@ -195,9 +195,9 @@ + (CGSize)calculateBackgroundImageSize:(const CGRect&)positioningArea
195195 if (itemFinalSize.width > 0 && positioningAreaSize.width > 0 ) {
196196 auto remainder = fmod (positioningAreaSize.width , itemFinalSize.width );
197197 if (!floatEquality (remainder, 0.0 )) {
198- auto alignedPositioningWidth = [RCTBackgroundImageUtils pixelAlign: positioningAreaSize.width] ;
199- auto alignedItemFinalWidth = [RCTBackgroundImageUtils pixelAlign: itemFinalSize.width] ;
200- auto divisor = round (alignedPositioningWidth / alignedItemFinalWidth );
198+ auto roundedPositioningWidth = round ( positioningAreaSize.width ) ;
199+ auto roundedItemFinalWidth = round ( itemFinalSize.width ) ;
200+ auto divisor = round (roundedPositioningWidth / roundedItemFinalWidth );
201201 if (divisor > 0 ) {
202202 itemFinalSize.width = positioningAreaSize.width / divisor;
203203 }
@@ -209,9 +209,9 @@ + (CGSize)calculateBackgroundImageSize:(const CGRect&)positioningArea
209209 if (itemFinalSize.height > 0 && positioningAreaSize.height > 0 ) {
210210 auto remainder = fmod (positioningAreaSize.height , itemFinalSize.height );
211211 if (!floatEquality (remainder, 0.0 )) {
212- auto alignedPositioningHeight = [RCTBackgroundImageUtils pixelAlign: positioningAreaSize.height] ;
213- auto alignedItemFinalHeight = [RCTBackgroundImageUtils pixelAlign: itemFinalSize.height] ;
214- auto divisor = round (alignedPositioningHeight / alignedItemFinalHeight );
212+ auto roundedPositioningHeight = round ( positioningAreaSize.height ) ;
213+ auto roundedItemFinalHeight = round ( itemFinalSize.height ) ;
214+ auto divisor = round (roundedPositioningHeight / roundedItemFinalHeight );
215215 if (divisor > 0 ) {
216216 itemFinalSize.height = positioningAreaSize.height / divisor;
217217 }
@@ -222,8 +222,4 @@ + (CGSize)calculateBackgroundImageSize:(const CGRect&)positioningArea
222222 return itemFinalSize;
223223}
224224
225- + (CGFloat)pixelAlign : (CGFloat)value {
226- return round (value * [UIScreen mainScreen ].scale ) / [UIScreen mainScreen ].scale ;
227- }
228-
229225@end
0 commit comments