Skip to content

Commit

Permalink
Merge pull request #3803 from bbirman/login-accessibility
Browse files Browse the repository at this point in the history
Resize navigation title for accessibility + IDs for UI automation
  • Loading branch information
bbirman authored Jan 15, 2025
2 parents 49ecb58 + 76d0e89 commit 0a3fdf9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class NewLoginHostViewController: NSObject {

struct NewLoginHostField: View {
let fieldLabel: String
let fieldLabelAccessibilityID: String
let fieldPlaceholder: String
let fieldInputAccessibilityID: String
@Binding var fieldValue: String

func placeholderText() -> Text {
Expand All @@ -50,7 +52,9 @@ struct NewLoginHostField: View {
var body: some View {
VStack(alignment: .leading, spacing: 5) {
Text(fieldLabel)
.accessibilityIdentifier(fieldLabelAccessibilityID)
TextField("", text: $fieldValue, prompt: placeholderText())
.accessibilityIdentifier(fieldInputAccessibilityID)
.autocorrectionDisabled()
.padding()
.background(
Expand Down Expand Up @@ -87,14 +91,18 @@ struct NewLoginHostView: View {
var body: some View {
List {
NewLoginHostField(fieldLabel: SFSDKResourceUtils.localizedString("LOGIN_SERVER_URL"),
fieldLabelAccessibilityID: "addconn_hostLabel",
fieldPlaceholder: SFSDKResourceUtils.localizedString("LOGIN_SERVER_URL_PLACEHOLDER"),
fieldInputAccessibilityID: "addconn_hostInput",
fieldValue: $host)
.keyboardType(.URL)
.autocapitalization(.none)
.listRowSeparator(.hidden)

NewLoginHostField(fieldLabel: SFSDKResourceUtils.localizedString("LOGIN_SERVER_NAME"),
fieldLabelAccessibilityID: "addconn_nameLabel",
fieldPlaceholder: SFSDKResourceUtils.localizedString("LOGIN_SERVER_NAME_PLACEHOLDER"),
fieldInputAccessibilityID: "addconn_nameInput",
fieldValue: $label)
.listRowSeparator(.hidden)
.padding(.bottom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ - (void)viewDidLoad {
if (bioAuthManager.locked && bioAuthManager.hasBiometricOptedIn) {
[bioAuthManager presentBiometricWithScene:self.view.window.windowScene];
}

[self registerForTraitChanges:@[UITraitDisplayScale.class] withAction:@selector(setupNavigationBar)];
}

- (CGFloat) belowFrame:(CGRect) frame {
Expand Down Expand Up @@ -195,34 +197,35 @@ - (void)setConfig:(SFSDKLoginViewControllerConfig *)config {
#pragma mark - Setup Navigation bar

- (void)setupNavigationBar {

self.navBar = self.navigationController.navigationBar;
self.navBar.topItem.titleView = [self createTitleItem];
// Hides the gear icon if there are no hosts to switch to.
SFManagedPreferences *managedPreferences = [SFManagedPreferences sharedPreferences];
if (managedPreferences.onlyShowAuthorizedHosts && managedPreferences.loginHosts.count == 0) {
self.config.showSettingsIcon = NO;
}
if(self.showSettingsIcon) {
// Setup right bar button.
UIBarButtonItem *button = [self createSettingsButton];
if (!button.target){
[button setTarget:self];
}
if (!button.action){
[button setAction:@selector(showLoginHost:)];
}
self.navBar.topItem.rightBarButtonItem = button;
}
[self styleNavigationBar:self.navBar];

if (self.navigationController == nil) {
[self.view addSubview:self.navBar];
}

#if !TARGET_OS_VISION
if (self.showNavbar) {
self.navBar = self.navigationController.navigationBar;
self.navBar.topItem.titleView = [self createTitleItem];
// Hides the gear icon if there are no hosts to switch to.
SFManagedPreferences *managedPreferences = [SFManagedPreferences sharedPreferences];
if (managedPreferences.onlyShowAuthorizedHosts && managedPreferences.loginHosts.count == 0) {
self.config.showSettingsIcon = NO;
}
if(self.showSettingsIcon) {
// Setup right bar button.
UIBarButtonItem *button = [self createSettingsButton];
if (!button.target){
[button setTarget:self];
}
if (!button.action){
[button setAction:@selector(showLoginHost:)];
}
self.navBar.topItem.rightBarButtonItem = button;
}
[self styleNavigationBar:self.navBar];
if (self.navigationController == nil) {
[self.view addSubview:self.navBar];
}
#if !TARGET_OS_VISION
[self setNeedsStatusBarAppearanceUpdate];
#endif
#endif
}
}

- (void)setupBackButton {
Expand Down Expand Up @@ -277,9 +280,13 @@ - (UIView *)createTitleItem {
}
if (self.config.navBarFont) {
item.font = self.config.navBarFont;
} else {
item.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
}

item.text = title;
[item sizeToFit];
item.textAlignment = NSTextAlignmentCenter;
item.adjustsFontForContentSizeCategory = YES;
return item;
}

Expand Down

0 comments on commit 0a3fdf9

Please sign in to comment.