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

Resize navigation title for accessibility + IDs for UI automation #3803

Merged
merged 2 commits into from
Jan 15, 2025
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 @@ -37,7 +37,9 @@ 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
Loading