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

Sync the codes release/v0.1 to main #17

Merged
merged 4 commits into from
May 30, 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
2 changes: 1 addition & 1 deletion FireworkVideoUI.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FireworkVideoUI'
s.version = '0.1.0'
s.version = '0.1.2'
s.summary = 'An extension library meant to provide easier interfaces for the FireworkVideoSDK.'
s.homepage = 'https://github.com/loopsocial/firework_ios_sdk_ui_extensions'
s.license = 'Apache License, Version 2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public class AppLanguageManager {
UIViewController.swizzleViewControllerMethodsForAppLanguage()
Bundle.swizzleBundleMethodsForAppLanguage()
URLSession.swizzleURLSessionMethodsForAppLanguage()
NumberFormatter.swizzleNumberFormatterMethodsForAppLanguage()
UIImageView.swizzleImageViewMethodsForAppLanguage()
UILabel.swizzleLabelMethodsForAppLanguage()
UITextField.swizzleTextFieldMethodsForAppLanguage()
UITextView.swizzleTextViewMethodsForAppLanguage()
UIWindow.swizzleWindowMethodsForAppLanguage()
UIView.swizzleViewMethodsForAppLanguage()
NSLocale.swizzleNSLocaleMethodsForAppLanguage()
}

LayoutFlipManager.swizzelMethods()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Locale+AppLanguage.swift
//
// Created by linjie jiang on 5/7/24.
//

import Foundation

extension NSLocale {
static func swizzleNSLocaleMethodsForAppLanguage() {
Swizzle.swizzleClassSelector(
cls: self,
originalSelector: #selector(getter: NSLocale.current),
customSelector: #selector(NSLocale.fw_current))
Swizzle.swizzleClassSelector(
cls: self,
originalSelector: #selector(getter: NSLocale.autoupdatingCurrent),
customSelector: #selector(NSLocale.fw_autoupdatingCurrent))
Swizzle.swizzleClassSelector(
cls: self,
originalSelector: #selector(getter: NSLocale.preferredLanguages),
customSelector: #selector(NSLocale.fw_preferredLanguages))
}

@objc class func fw_current() -> Locale {
if let language = AppLanguageManager.shared.appLanguage {
return Locale(identifier: language)
}

return fw_current()
}

@objc class func fw_autoupdatingCurrent() -> Locale {
if let language = AppLanguageManager.shared.appLanguage {
return Locale(identifier: language)
}

return fw_autoupdatingCurrent()
}

@objc class func fw_preferredLanguages() -> [String] {
let languages = fw_preferredLanguages()
if let language = AppLanguageManager.shared.appLanguage {
return [language] + languages
}

return languages
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit

extension UILabel {
private struct AssociatedKeys {
static var hasCalculatedTextAlignment = "hasCalculatedTextAlignmentKey"
static var hasCalculatedTextAlignment: UInt8 = 0
}

private var hasCalculatedTextAlignment: Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit

extension UITextField {
private struct AssociatedKeys {
static var hasCalculatedTextAlignment = "hasCalculatedTextAlignmentKey"
static var hasCalculatedTextAlignment: UInt8 = 0
}

private var hasCalculatedTextAlignment: Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit

extension UITextView {
private struct AssociatedKeys {
static var hasCalculatedTextAlignment = "hasCalculatedTextAlignmentKey"
static var hasCalculatedTextAlignment: UInt8 = 0
}

private var hasCalculatedTextAlignment: Bool {
Expand Down
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 @@ -60,7 +64,35 @@ extension UIView {
view.viewType = .normal
}

let swiftUIImageLayerClassName = "SW1hZ2VMYXllcg==".decodeBase64String()
let swiftUITextLayerClassName = "Q0dEcmF3aW5nTGF5ZXI=".decodeBase64String()
let layerClassName = String(describing: type(of: self.layer))

if AppLanguageManager.shared.shouldHorizontalFlip,
layerClassName == swiftUITextLayerClassName ||
layerClassName == swiftUIImageLayerClassName {
view.viewType = .normal
}

DispatchQueue.main.async {
if AppLanguageManager.shared.shouldHorizontalFlip,
layerClassName == swiftUIImageLayerClassName,
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 {
view.viewType = .flip
break
}
}
}

if view.layer.sublayers?.first(where: { layer in
layer is AVPlayerLayer
}) != nil, AppLanguageManager.shared.shouldHorizontalFlip {
Expand Down
17 changes: 16 additions & 1 deletion Sources/FireworkVideoUI/Extensions/ObjCRuntime/Swizzle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ public class Swizzle {
guard let originalMethod = class_getClassMethod(cls, originalSelector) else { return }
guard let customMethod = class_getClassMethod(cls, customSelector) else { return }

method_exchangeImplementations(originalMethod, customMethod)
let clsType: AnyClass? = object_getClass(cls)
if class_addMethod(
clsType,
originalSelector,
method_getImplementation(customMethod),
method_getTypeEncoding(customMethod)
) {
class_replaceMethod(
clsType,
customSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod)
)
} else {
method_exchangeImplementations(originalMethod, customMethod)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typealias ReloadClosure = () -> Void

extension NSObject {
private struct AssociatedKeys {
static var reloadClosures = "reloadBlocks"
static var reloadClosures: UInt8 = 0
}

private var reloadClosures: [String: ReloadClosure] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import UIKit

extension CALayer {
private struct AssociatedKeys {
static var basicTransform = "basicTransform"
static var isRenderStartLayer = "isRenderStartLayer"
static var affineTransform = "affineTransform"
static var basicTransform: UInt8 = 0
static var isRenderStartLayer: UInt8 = 0
static var affineTransform: UInt8 = 0
}

static func swizzleLayerMethodsForLayoutFlip() {
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 All @@ -32,9 +32,9 @@ enum LayoutFlipViewType: Int {

extension UIView {
private struct AssociatedKeys {
static var viewType = "viewType"
static var calculatedViewType = "calculatedViewType"
static var lastType = "lastType"
static var viewType: UInt8 = 0
static var calculatedViewType: UInt8 = 0
static var lastType: UInt8 = 0
}

static func swizzleViewMethodsForLayoutFlip() {
Expand All @@ -50,6 +50,10 @@ extension UIView {
cls: self,
originalSelector: #selector(UIView.snapshotView(afterScreenUpdates:)),
customSelector: #selector(UIView.fw_snapshotView(afterScreenUpdates:)))
Swizzle.swizzleSelector(
cls: self,
originalSelector: #selector(UIView.layoutSubviews),
customSelector: #selector(UIView.fw_layoutSubviews))
}

var viewType: LayoutFlipViewType {
Expand Down Expand Up @@ -137,6 +141,11 @@ extension UIView {
return view
}

@objc func fw_layoutSubviews() {
fw_layoutSubviews()
renewLayerTransformForceRecursively(false)
}

func renewLayerTransformForceRecursively(_ forceRecursively: Bool) {
if !isIOSSDKView {
return
Expand All @@ -151,7 +160,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