Skip to content

Commit

Permalink
Bug fix: [Flutter SDK] [RTL] Some of the images/texts are in the wron…
Browse files Browse the repository at this point in the history
…g direction (#15)

* Bug fix: [Flutter SDK] [RTL] Some of the images/texts are in the wrong direction

* Update UIView+AppLanguage.swift
  • Loading branch information
linjie-firework authored May 20, 2024
1 parent f88acaf commit 7919b0b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import UIKit
import FireworkVideo
import AVFoundation

private let gNamesOfImagesWithDirection: [String] = [
"c3RyZWFtLWdhdGUtYmFjaw==".decodeBase64String(),
]

extension UIView {
static func swizzleViewMethodsForAppLanguage() {
Swizzle.swizzleSelector(
Expand Down Expand Up @@ -61,6 +65,33 @@ extension UIView {
}

DispatchQueue.main.async {
if AppLanguageManager.shared.shouldHorizontalFlip {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ private let gNoFlipClasses: [Any] = [
"PUPhotosSectionHeaderContentView",
"UITableViewIndex",
"UIWebView",
"X1VJUmVtb3RlVmlldw==".decodeBase64String(), // _UIRemoteView
"VUlBdXRvY29ycmVjdFRleHRWaWV3".decodeBase64String() // UIAutocorrectTextView
"X1VJUmVtb3RlVmlldw==".decodeBase64String(),
"VUlBdXRvY29ycmVjdFRleHRWaWV3".decodeBase64String(),
]

enum LayoutFlipViewType: Int {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7919b0b

Please sign in to comment.