Skip to content

Commit

Permalink
fixes navigation drag to go back gesture direction
Browse files Browse the repository at this point in the history
  • Loading branch information
dark2torch committed Nov 12, 2020
1 parent 5fb09bd commit c78502b
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -38,8 +36,8 @@
ReferencedContainer = "container:LocalizationHelperDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -61,8 +59,6 @@
ReferencedContainer = "container:LocalizationHelperDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
"localize me please" = "localize me please";
"localize_me_please" = "localize me please base";
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="2QC-AV-CKr">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="2QC-AV-CKr">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -14,7 +12,7 @@
<objects>
<navigationController storyboardIdentifier="rootnav" id="2QC-AV-CKr" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="2mX-2z-pfs">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand All @@ -38,7 +36,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="11" translatesAutoresizingMaskIntoConstraints="NO" id="tXQ-GK-My7">
<rect key="frame" x="20" y="79" width="131" height="168"/>
<rect key="frame" x="20" y="59" width="131" height="168"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" tag="-1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hello " textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XqB-5F-EF1">
<rect key="frame" x="0.0" y="0.0" width="43.5" height="20.5"/>
Expand All @@ -53,7 +51,7 @@
<constraint firstAttribute="height" constant="32" id="wnN-l3-z6x"/>
</constraints>
</imageView>
<button opaque="NO" tag="-1" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jMW-hU-lgc">
<button opaque="NO" tag="-1" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jMW-hU-lgc">
<rect key="frame" x="0.0" y="74.5" width="131" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="H5T-Sy-0RD"/>
Expand All @@ -64,7 +62,7 @@
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" tag="-2" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qa0-jT-D1A">
<rect key="frame" x="0.0" y="115.5" width="42" height="20.5"/>
<rect key="frame" x="0.0" y="115.5" width="41.5" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
Expand All @@ -77,21 +75,20 @@
</label>
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Cje-ky-EQg">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Cje-ky-EQg">
<rect key="frame" x="130" y="416.5" width="118" height="30"/>
<state key="normal" title="Switch Language"/>
<connections>
<action selector="switchTheLanguage:" destination="BYZ-38-t0r" eventType="touchUpInside" id="hnH-TR-2p8"/>
</connections>
</button>
<textField opaque="NO" clipsSubviews="YES" tag="-1" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="bezel" placeholder="TextField Case" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="fiM-aM-EMW">
<rect key="frame" x="130" y="306.5" width="115.5" height="30"/>
<textField opaque="NO" clipsSubviews="YES" tag="-1" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="bezel" placeholder="TextField Case" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="fiM-aM-EMW" customClass="TextView" customModule="LocalizationHelperDemo" customModuleProvider="target">
<rect key="frame" x="126.5" y="306.5" width="122.5" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="cG1-lk-tpQ"/>
</constraints>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<textInputTraits key="textInputTraits" keyboardType="phonePad"/>
<connections>
<action selector="didEnd:" destination="BYZ-38-t0r" eventType="editingDidEnd" id="vvM-lD-7bI"/>
<action selector="end:" destination="BYZ-38-t0r" eventType="editingDidEndOnExit" id="wFv-Ng-9IL"/>
Expand Down
194 changes: 189 additions & 5 deletions LocalizationHelperDemo/LocalizationHelperDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
class ViewController: UIViewController {
@IBOutlet weak var programmaticallylocalizedLabel: UILabel!
@IBOutlet var labelWithFont: MOLHFontLocalizableLabel!
@IBOutlet var textField: UITextField!
@IBOutlet var textField: TextView!
@IBOutlet var arrowImage: UIImageView! {
didSet {
arrowImage.image = arrowImage.image?.flipIfNeeded()
Expand All @@ -21,18 +21,42 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// textField.forceSwitchingRegardlessOfTag = true
self.programmaticallylocalizedLabel.text = NSLocalizedString("localize me please", comment: "Localize me Label in the main scene")
self.programmaticallylocalizedLabel.text = NSLocalizedString("localize_me_please", comment: "Localize me Label in the main scene")

self.labelWithFont.updateFont()
// NotificationCenter.default.addObserver(self, selector: #selector(inputModeDidChange), name: .UITextInputCurrentInputModeDidChange, object: nil)

let identifiers : NSArray = NSLocale.availableLocaleIdentifiers as NSArray
let locale = NSLocale(localeIdentifier: "en_US")
let list = NSMutableString()
for identifier in identifiers {
let name = locale.displayName(forKey: NSLocale.Key.identifier, value: identifier)!
list.append("\(identifier)\t\(name)\n")
}
if #available(iOS 13.0, *) {
labelWithFont.isUserInteractionEnabled = true
let interaction = UIContextMenuInteraction(delegate: self)
labelWithFont.addInteraction(interaction)

} else {
// Fallback on earlier versions
}
self.programmaticallylocalizedLabel.text = Locale.current.identifier
// let view = UIView()
// view.frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 400))
// view.backgroundColor = .red
// print("current local", Locale.current.identifier)
// textField.inputView = view
NotificationCenter.default.addObserver(self, selector: #selector(inputModeDidChange), name: UITextInputMode.currentInputModeDidChangeNotification, object: nil)
}

// @objc func inputModeDidChange(_ notification: Notification) {
@objc func inputModeDidChange(_ notification: Notification) {

// if let language = self.textInputMode?.primaryLanguage, MOLHLanguage.isRTLLanguage(language: language) {
// textField.textAlignment = .right
// } else {
// textField.textAlignment = .left
// }
// }
}

@IBAction func switchTheLanguage(_ sender: UIButton) {
MOLH.setLanguageTo(MOLHLanguage.currentAppleLanguage() == "en" ? "ar" : "en")
Expand All @@ -47,6 +71,166 @@ class ViewController: UIViewController {
sender.resignFirstResponder()
}




// override var textInputMode: UITextInputMode?{
// print("Total number of keyboards. : \(UITextInputMode.activeInputModes.count)")
//
// for keyboardInputModes in UITextInputMode.activeInputModes {
// if let language = keyboardInputModes.primaryLanguage {
// if language == "ar" {
// print("success")
// return keyboardInputModes;
// }
// }
// }
//
// print("failed")
// return super.textInputMode;
// }
}

//extension UIResponder {
// open var textInputMode: UITextInputMode? {
// CustomTextInput()
// }
//}

class CustomTextInput: UITextInputMode {
override var primaryLanguage: String? {
return "fr"
}
}

extension UIViewController {
@objc open override var textInputMode: UITextInputMode? {
CustomTextInput()
}
}

final class TextView: UITextField {
// private var preferredTextInputModePrimaryLanguage: String? = "en"
//
// /**
// Use given primary language for the preferred text input mode when next time text view becomes first responder.
// - Parameters:
// - primaryLanguage: `String` represents a primary language for the preferred text input mode. Use `"emoji"` to use Emoji keyboard.
// */
// func usePreferredTextInputModePrimaryLanguage(_ primaryLanguage: String) {
// preferredTextInputModePrimaryLanguage = primaryLanguage
// }
//
// /**
// # UIKit Bug Workaround
// - Confirmed on iOS 13.0 to iOS 13.3.
// - Fixed on iOS 13.4.
// `textInputMode` override is completely ignored on these version of iOS 13 due to bug in `-[UIKeyboardImpl recomputeActiveInputModesWithExtensions:allowNonLinguisticInputModes:]`,
// which has a flipped condition check, which doesn't always call `-[UIKeyboardImpl setInputMode:userInitiated:]`.
// To workaround this behavior, return non `nil` identifier from `textInputContextIdentifier` to call `-[UIKeyboardImpl setInputMode:userInitiated:]` from
// `-[UIKeyboardInputModeController _trackInputModeIfNecessary:]` and bypass `-[UIKeyboardImpl recomputeActiveInputModesWithExtensions:allowNonLinguisticInputModes:]` call.
// Also need to clean up text input context identifier once it’s used for the bug workaround.
// - See also:
// - `becomeFirstResponder()`
// - `textInputContextIdentifier`
// - `textInputMode`
// */
// private let shouldWorkaroundTextInputModeBug: Bool = {
// // iOS 13.0 to iOS 13.3
// if #available(iOS 13.0, *) {
// if #available(iOS 13.4, *) {
// return false
// } else {
// return true
// }
// }
// return false
// }()
//
// private let preferredTextInputModeContextIdentifier = ".preferredTextInputModeContextIdentifier"
//
// override func becomeFirstResponder() -> Bool {
// let result = super.becomeFirstResponder()
// if result {
// if shouldWorkaroundTextInputModeBug {
// UIResponder.clearTextInputContextIdentifier(preferredTextInputModeContextIdentifier)
// }
// preferredTextInputModePrimaryLanguage = "en"
// }
// return result
// }
//
// override var textInputContextIdentifier: String? {
// if shouldWorkaroundTextInputModeBug, preferredTextInputModePrimaryLanguage != nil {
// return preferredTextInputModeContextIdentifier
// }
//
// return super.textInputContextIdentifier
// }
//
// override var textInputMode: UITextInputMode? {
// if
// let inputMode = UITextInputMode.activeInputModes.first(where: { $0.primaryLanguage?.contains("en") ?? false }) {
// return inputMode
// }
//
// return super.textInputMode
// }
}

extension ViewController: UIContextMenuInteractionDelegate {
@available(iOS 13.0, *)
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {

if #available(iOS 13.0, *) {

let identifier = "\(location.debugDescription)" as NSString

let info = UIAction(
title: "ارابيم",
image: UIImage(systemName: "info.circle")) { _ in
}
let mute = UIAction(
title: "L10n.mute",
image: UIImage(systemName: "speaker.slash")) { _ in
//self.showAlert("Error", message: "Implement mute action", handler: nil)
}

let delete = UIAction(
title: "زيايل",
image: UIImage(systemName: "trash")) { _ in

}

let audioCall = UIAction(
title: "نمستي رخه",
image: UIImage(systemName: "phone")) { _ in
}

let videoCall = UIAction(
title: "L10n.videoCall",
image: UIImage(systemName: "video")) { _ in
}

_ = UIAction(
title: "L10n.exitGroup",
image: UIImage(systemName: "person.3")) { _ in
}

var menu = UIMenu()

menu = UIMenu(title: "", children: [info, mute, delete, audioCall, videoCall])


return UIContextMenuConfiguration(
identifier: identifier,
previewProvider: nil) { _ in
return menu
}
} else {
// Fallback on earlier versions
return nil
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
"localize me please" = "localize me please";
"localize_me_please" = "localize me please cameroon";
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
"localize me please" = "لوكالايز مي";
"localize_me_please" = "لوكالايز مي";
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
"localize me please" = "localize me please";
"localize_me_please" = "localize me please sorani";
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
"localize me please" = "localize me please";
"localize_me_please" = "localize me please sorani";
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
"localize me please" = "localize me please";
"localize_me_please" = "localize me please";
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
"localize me please" = "localize me please";
"localize_me_please" = "localize me please hebrew";
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
"localize me please" = "localize me please";
"localize_me_please" = "localize me please urdu";
Loading

0 comments on commit c78502b

Please sign in to comment.