Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
]
Comment on lines +11 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This base64 decoded string seems to be referencing and internal image of the FireworkVideoSDK. This is extremely fragile. What is the intent on this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find the other way instead of hardcoding FireworkVideoSDK image names here. The image is used in SwiftUI. We don't have another way to check whether the image should be flipped. For the image used in UIImageView, we could check the flipsForRightToLeftLayoutDirection property. But we can't find the related property in SwiftUI.


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
Loading