From d688fbc0413786eb92a6ad22f6b6bc225869bc62 Mon Sep 17 00:00:00 2001 From: Jayden Date: Thu, 16 May 2024 14:51:18 +0800 Subject: [PATCH 1/2] Bug fix: [Flutter SDK] [RTL] Some of the images/texts are in the wrong direction --- .../Extensions/UIKit/UIView+AppLanguage.swift | 33 +++++++++++++++++++ .../Extensions/UIKit/UIView+LayoutFlip.swift | 10 ++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Sources/FireworkVideoUI/AppLanguage/Extensions/UIKit/UIView+AppLanguage.swift b/Sources/FireworkVideoUI/AppLanguage/Extensions/UIKit/UIView+AppLanguage.swift index 8893eca..8943ae6 100644 --- a/Sources/FireworkVideoUI/AppLanguage/Extensions/UIKit/UIView+AppLanguage.swift +++ b/Sources/FireworkVideoUI/AppLanguage/Extensions/UIKit/UIView+AppLanguage.swift @@ -8,6 +8,10 @@ import UIKit import FireworkVideo import AVFoundation +private let gNamesOfImagesWithDirection: [String] = [ + "stream-gate-back", +] + extension UIView { static func swizzleViewMethodsForAppLanguage() { Swizzle.swizzleSelector( @@ -61,6 +65,35 @@ extension UIView { } DispatchQueue.main.async { + if AppLanguageManager.shared.shouldHorizontalFlip { + // ImageLayer + // CGDrawingLayer + let swiftUIImageLayerClassName = "SW1hZ2VMYXllcg==".decodeBase64String() + let swiftUITextLayerClassName = "Q0dEcmF3aW5nTGF5ZXI=".decodeBase64String() + let layerClassName = String(describing: type(of: self.layer)) + if layerClassName == swiftUITextLayerClassName { + view.viewType = .normal + } else if layerClassName == swiftUIImageLayerClassName { + var resultViewType = LayoutFlipViewType.normal + if let contents = self.layer.contents as? CFTypeRef, + CFGetTypeID(contents) == CGImage.typeID { + let image = self.layer.contents as! CGImage + for imageName in gNamesOfImagesWithDirection { + let imageWithDirection = UIImage( + named: imageName, + in: Bundle(for: FireworkVideoSDK.self), + compatibleWith: nil + )?.cgImage + if image == imageWithDirection { + resultViewType = .flip + break + } + } + } + view.viewType = resultViewType + } + } + if view.layer.sublayers?.first(where: { layer in layer is AVPlayerLayer }) != nil, AppLanguageManager.shared.shouldHorizontalFlip { diff --git a/Sources/FireworkVideoUI/LayoutFlip/Extensions/UIKit/UIView+LayoutFlip.swift b/Sources/FireworkVideoUI/LayoutFlip/Extensions/UIKit/UIView+LayoutFlip.swift index c23bb00..9577206 100644 --- a/Sources/FireworkVideoUI/LayoutFlip/Extensions/UIKit/UIView+LayoutFlip.swift +++ b/Sources/FireworkVideoUI/LayoutFlip/Extensions/UIKit/UIView+LayoutFlip.swift @@ -17,8 +17,8 @@ private let gNoFlipClasses: [Any] = [ "PUPhotosSectionHeaderContentView", "UITableViewIndex", "UIWebView", - "X1VJUmVtb3RlVmlldw==".decodeBase64String(), // _UIRemoteView - "VUlBdXRvY29ycmVjdFRleHRWaWV3".decodeBase64String() // UIAutocorrectTextView + "X1VJUmVtb3RlVmlldw==".decodeBase64String(), + "VUlBdXRvY29ycmVjdFRleHRWaWV3".decodeBase64String(), ] enum LayoutFlipViewType: Int { @@ -151,7 +151,11 @@ extension UIView { let shouldSetFlipTransform = shouldFlipSuperview != shouldFlipCurrentView if shouldSetFlipTransform && LayoutFlipManager.shared.enableHorizontalFlip { - layer.basicTransform = CGAffineTransformMakeScale(-1, 1) + if layer.anchorPoint == CGPointZero { + layer.basicTransform = CGAffineTransformConcat(CGAffineTransformMakeScale(-1, 1), CGAffineTransform(translationX: layer.bounds.width, y: 0)) + } else { + layer.basicTransform = CGAffineTransformMakeScale(-1, 1) + } } else { layer.basicTransform = CGAffineTransformIdentity } From ea67c134e4ab719dc7dc1be4af45bf05ee6149d2 Mon Sep 17 00:00:00 2001 From: Jayden Date: Thu, 16 May 2024 14:57:27 +0800 Subject: [PATCH 2/2] Update UIView+AppLanguage.swift --- .../AppLanguage/Extensions/UIKit/UIView+AppLanguage.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/FireworkVideoUI/AppLanguage/Extensions/UIKit/UIView+AppLanguage.swift b/Sources/FireworkVideoUI/AppLanguage/Extensions/UIKit/UIView+AppLanguage.swift index 8943ae6..914642e 100644 --- a/Sources/FireworkVideoUI/AppLanguage/Extensions/UIKit/UIView+AppLanguage.swift +++ b/Sources/FireworkVideoUI/AppLanguage/Extensions/UIKit/UIView+AppLanguage.swift @@ -9,7 +9,7 @@ import FireworkVideo import AVFoundation private let gNamesOfImagesWithDirection: [String] = [ - "stream-gate-back", + "c3RyZWFtLWdhdGUtYmFjaw==".decodeBase64String(), ] extension UIView { @@ -66,8 +66,6 @@ extension UIView { DispatchQueue.main.async { if AppLanguageManager.shared.shouldHorizontalFlip { - // ImageLayer - // CGDrawingLayer let swiftUIImageLayerClassName = "SW1hZ2VMYXllcg==".decodeBase64String() let swiftUITextLayerClassName = "Q0dEcmF3aW5nTGF5ZXI=".decodeBase64String() let layerClassName = String(describing: type(of: self.layer))