Skip to content

Commit

Permalink
Add objective C support to SwiftGen assets helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
aringenbach committed Feb 9, 2022
1 parent 70d5fbd commit 086d053
Show file tree
Hide file tree
Showing 42 changed files with 499 additions and 152 deletions.
8 changes: 4 additions & 4 deletions Riot/Categories/MXKRoomBubbleTableViewCell+Riot.m
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ - (void)updateTickViewWithFailedEventIds:(NSSet *)failedEventIds
if ([bubbleData isKindOfClass:RoomBubbleCellData.class]
&& ((RoomBubbleCellData*)bubbleData).componentIndexOfSentMessageTick >= 0)
{
UIImage *image = [UIImage imageNamed:@"sent_message_tick"];
UIImage *image = [[AssetImages sentMessageTick] image];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
tickView = [[UIImageView alloc] initWithImage:image];
tickView.tintColor = ThemeService.shared.theme.textTertiaryColor;
Expand Down Expand Up @@ -733,7 +733,7 @@ - (void)updateTickViewWithFailedEventIds:(NSSet *)failedEventIds
}
else
{
UIImage *image = [UIImage imageNamed:@"sending_message_tick"];
UIImage *image = [[AssetImages sendingMessageTick] image];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
tickView = [[UIImageView alloc] initWithImage:image];
tickView.tintColor = ThemeService.shared.theme.textTertiaryColor;
Expand All @@ -746,7 +746,7 @@ - (void)updateTickViewWithFailedEventIds:(NSSet *)failedEventIds

if (component.event.sentState == MXEventSentStateFailed)
{
tickView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error_message_tick"]];
tickView = [[UIImageView alloc] initWithImage:[[AssetImages errorMessageTick] image]];
[statusViews addObject:tickView];
[self addTickView:tickView atIndex:index];
}
Expand Down Expand Up @@ -815,7 +815,7 @@ - (void)addEditButtonForComponent:(NSUInteger)componentIndex completion:(void (^
}

// Define 'Edit' button frame
UIImage *editIcon = [UIImage imageNamed:@"edit_icon"];
UIImage *editIcon = [[AssetImages editIcon] image];
CGFloat editBtnPosX = self.bubbleInfoContainer.frame.size.width - RoomBubbleCellLayout.timestampLabelWidth - 22 - editIcon.size.width / 2;
CGFloat editBtnPosY = isFirstDisplayedComponent ? -13 : component.position.y + self.msgTextViewTopConstraint.constant - self.bubbleInfoContainerTopConstraint.constant - 13;
UIButton *editButton = [[UIButton alloc] initWithFrame:CGRectMake(editBtnPosX, editBtnPosY, 44, 44)];
Expand Down
2 changes: 1 addition & 1 deletion Riot/Categories/UIViewController+RiotSearch.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ - (void)hideSearch:(BOOL)animated

- (void)addBackgroundImageViewToView:(UIView*)view
{
UIImage *searchBgImage = [MXKTools paintImage:[UIImage imageNamed:@"search_bg"] withColor:ThemeService.shared.theme.matrixSearchBackgroundImageTintColor];
UIImage *searchBgImage = [MXKTools paintImage:[[AssetImages searchBg] image] withColor:ThemeService.shared.theme.matrixSearchBackgroundImageTintColor];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:searchBgImage];
backgroundImageView.translatesAutoresizingMaskIntoConstraints = NO;

Expand Down
17 changes: 13 additions & 4 deletions Riot/Generated/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ internal typealias AssetImageTypeAlias = ImageAsset.Image
// MARK: - Asset Catalogs

// swiftlint:disable identifier_name line_length nesting type_body_length type_name
internal enum Asset {
internal enum Images {
@objcMembers
internal class Asset: NSObject {
@objcMembers
@objc(AssetImages) internal class Images: NSObject {
internal static let analyticsCheckmark = ImageAsset(name: "AnalyticsCheckmark")
internal static let analyticsLogo = ImageAsset(name: "AnalyticsLogo")
internal static let socialLoginButtonApple = ImageAsset(name: "social_login_button_apple")
Expand Down Expand Up @@ -237,7 +239,8 @@ internal enum Asset {
internal static let tabRooms = ImageAsset(name: "tab_rooms")
internal static let launchScreenLogo = ImageAsset(name: "launch_screen_logo")
}
internal enum SharedImages {
@objcMembers
@objc(AssetSharedImages) internal class SharedImages: NSObject {
internal static let cancel = ImageAsset(name: "cancel")
internal static let e2eVerified = ImageAsset(name: "e2e_verified")
internal static let horizontalLogo = ImageAsset(name: "horizontal_logo")
Expand All @@ -249,7 +252,8 @@ internal enum Asset {

// MARK: - Implementation Details

internal struct ImageAsset {
@objcMembers
internal class ImageAsset: NSObject {
internal fileprivate(set) var name: String

#if os(macOS)
Expand All @@ -275,6 +279,10 @@ internal struct ImageAsset {
return result
}

init(name: String) {
self.name = name
}

#if os(iOS) || os(tvOS)
@available(iOS 8.0, tvOS 9.0, *)
internal func image(compatibleWith traitCollection: UITraitCollection) -> Image {
Expand Down Expand Up @@ -314,3 +322,4 @@ private final class BundleToken {
}()
}
// swiftlint:enable convenience_type

10 changes: 5 additions & 5 deletions Riot/Modules/Authentication/AuthenticationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ - (void)viewDidLoad

self.defaultIdentityServerUrl = RiotSettings.shared.identityServerUrlString;

self.welcomeImageView.image = [UIImage imageNamed:@"horizontal_logo"];
self.welcomeImageView.image = [[AssetSharedImages horizontalLogo] image];

[self.submitButton.layer setCornerRadius:5];
self.submitButton.clipsToBounds = YES;
Expand All @@ -150,8 +150,8 @@ - (void)viewDidLoad
[self.skipButton setTitle:[VectorL10n authSkip] forState:UIControlStateHighlighted];
self.skipButton.enabled = YES;

[self.customServersTickButton setImage:[UIImage imageNamed:@"selection_untick"] forState:UIControlStateNormal];
[self.customServersTickButton setImage:[UIImage imageNamed:@"selection_untick"] forState:UIControlStateHighlighted];
[self.customServersTickButton setImage:[[AssetImages selectionUntick] image] forState:UIControlStateNormal];
[self.customServersTickButton setImage:[[AssetImages selectionUntick] image] forState:UIControlStateHighlighted];

if (!BuildSettings.authScreenShowRegister)
{
Expand Down Expand Up @@ -1272,7 +1272,7 @@ - (void)hideCustomServers:(BOOL)hidden
[self setHomeServerTextFieldText:self.defaultHomeServerUrl];
[self setIdentityServerTextFieldText:self.defaultIdentityServerUrl];

[self.customServersTickButton setImage:[UIImage imageNamed:@"selection_untick"] forState:UIControlStateNormal];
[self.customServersTickButton setImage:[[AssetImages selectionUntick] image] forState:UIControlStateNormal];
self.customServersContainer.hidden = YES;

// Refresh content view height
Expand All @@ -1296,7 +1296,7 @@ - (void)hideCustomServers:(BOOL)hidden
[self setIdentityServerTextFieldText:customIdentityServerURL];
}

[self.customServersTickButton setImage:[UIImage imageNamed:@"selection_tick"] forState:UIControlStateNormal];
[self.customServersTickButton setImage:[[AssetImages selectionTick] image] forState:UIControlStateNormal];
self.customServersContainer.hidden = NO;

// Refresh content view height
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Authentication/Views/AuthInputsView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ - (IBAction)selectPhoneNumberCountry:(id)sender

[phoneNumberPickerNavigationController pushViewController:phoneNumberCountryPicker animated:NO];

UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_icon"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissCountryPicker)];
UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[AssetImages backIcon] image] style:UIBarButtonItemStylePlain target:self action:@selector(dismissCountryPicker)];
phoneNumberCountryPicker.navigationItem.leftBarButtonItem = leftBarButtonItem;

[self.delegate authInputsView:self presentViewController:phoneNumberPickerNavigationController animated:YES];
Expand Down
8 changes: 4 additions & 4 deletions Riot/Modules/BugReport/BugReportViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ - (void)setSendLogs:(BOOL)sendLogs
_sendLogs = sendLogs;
if (_sendLogs)
{
_sendLogsButtonImage.image = [UIImage imageNamed:@"selection_tick"];
_sendLogsButtonImage.image = [[AssetImages selectionTick] image];
}
else
{
_sendLogsButtonImage.image = [UIImage imageNamed:@"selection_untick"];
_sendLogsButtonImage.image = [[AssetImages selectionUntick] image];
}
}

Expand All @@ -235,11 +235,11 @@ - (void)setSendScreenshot:(BOOL)sendScreenshot
_sendScreenshot = sendScreenshot;
if (_sendScreenshot)
{
_sendScreenshotButtonImage.image = [UIImage imageNamed:@"selection_tick"];
_sendScreenshotButtonImage.image = [[AssetImages selectionTick] image];
}
else
{
_sendScreenshotButtonImage.image = [UIImage imageNamed:@"selection_untick"];
_sendScreenshotButtonImage.image = [[AssetImages selectionUntick] image];
}
}

Expand Down
24 changes: 12 additions & 12 deletions Riot/Modules/Call/CallViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,44 +73,44 @@ - (void)viewDidLoad

// Back button

UIImage *backButtonImage = [UIImage imageNamed:@"back_icon"];
UIImage *backButtonImage = [[AssetImages backIcon] image];
[self.backToAppButton setImage:backButtonImage forState:UIControlStateNormal];
[self.backToAppButton setImage:backButtonImage forState:UIControlStateHighlighted];

// Camera switch

UIImage *cameraSwitchButtonImage = [UIImage imageNamed:@"camera_switch"];
UIImage *cameraSwitchButtonImage = [[AssetImages cameraSwitch] image];
[self.cameraSwitchButton setImage:cameraSwitchButtonImage forState:UIControlStateNormal];
[self.cameraSwitchButton setImage:cameraSwitchButtonImage forState:UIControlStateHighlighted];

// Audio mute

UIImage *audioMuteOffButtonImage = [UIImage imageNamed:@"call_audio_mute_off_icon"];
UIImage *audioMuteOnButtonImage = [UIImage imageNamed:@"call_audio_mute_on_icon"];
UIImage *audioMuteOffButtonImage = [[AssetImages callAudioMuteOffIcon] image];
UIImage *audioMuteOnButtonImage = [[AssetImages callAudioMuteOnIcon] image];

[self.audioMuteButton setImage:audioMuteOffButtonImage forState:UIControlStateNormal];
[self.audioMuteButton setImage:audioMuteOffButtonImage forState:UIControlStateHighlighted];
[self.audioMuteButton setImage:audioMuteOnButtonImage forState:UIControlStateSelected];

// Video mute

UIImage *videoOffButtonImage = [UIImage imageNamed:@"call_video_mute_off_icon"];
UIImage *videoOnButtonImage = [UIImage imageNamed:@"call_video_mute_on_icon"];
UIImage *videoOffButtonImage = [[AssetImages callVideoMuteOffIcon] image];
UIImage *videoOnButtonImage = [[AssetImages callVideoMuteOnIcon] image];

[self.videoMuteButton setImage:videoOffButtonImage forState:UIControlStateNormal];
[self.videoMuteButton setImage:videoOffButtonImage forState:UIControlStateHighlighted];
[self.videoMuteButton setImage:videoOnButtonImage forState:UIControlStateSelected];

// More

UIImage *moreButtonImage = [UIImage imageNamed:@"call_more_icon"];
UIImage *moreButtonImage = [[AssetImages callMoreIcon] image];

[self.moreButtonForVoice setImage:moreButtonImage forState:UIControlStateNormal];
[self.moreButtonForVideo setImage:moreButtonImage forState:UIControlStateNormal];

// Hang up

UIImage *hangUpButtonImage = [UIImage imageNamed:@"call_hangup_large"];
UIImage *hangUpButtonImage = [[AssetImages callHangupLarge] image];

[self.endCallButton setTitle:nil forState:UIControlStateNormal];
[self.endCallButton setTitle:nil forState:UIControlStateHighlighted];
Expand Down Expand Up @@ -269,17 +269,17 @@ - (void)configureSpeakerButton
switch (self.mxCall.audioOutputRouter.currentRoute.routeType)
{
case MXiOSAudioOutputRouteTypeBuiltIn:
[self.speakerButton setImage:[UIImage imageNamed:@"call_speaker_off_icon"]
[self.speakerButton setImage:[[AssetImages callSpeakerOffIcon] image]
forState:UIControlStateNormal];
break;
case MXiOSAudioOutputRouteTypeLoudSpeakers:
[self.speakerButton setImage:[UIImage imageNamed:@"call_speaker_on_icon"]
[self.speakerButton setImage:[[AssetImages callSpeakerOnIcon] image]
forState:UIControlStateNormal];
break;
case MXiOSAudioOutputRouteTypeExternalWired:
case MXiOSAudioOutputRouteTypeExternalBluetooth:
case MXiOSAudioOutputRouteTypeExternalCar:
[self.speakerButton setImage:[UIImage imageNamed:@"call_speaker_external_icon"]
[self.speakerButton setImage:[[AssetImages callSpeakerExternalIcon] image]
forState:UIControlStateNormal];
break;
}
Expand Down Expand Up @@ -484,7 +484,7 @@ - (UIImage*)picturePlaceholder
andFontSize:fontSize];
}

return [MXKTools paintImage:[UIImage imageNamed:@"placeholder"]
return [MXKTools paintImage:[[AssetImages placeholder] image]
withColor:self.overriddenTheme.tintColor];
}

Expand Down
4 changes: 2 additions & 2 deletions Riot/Modules/Call/Views/IncomingCallView.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (instancetype)initWithCallerAvatar:(NSString *)mxcAvatarURI

UIColor *answerButtonBorderColor = ThemeService.shared.theme.tintColor;

self.answerButton = [[CircleButton alloc] initWithImage:[UIImage imageNamed:@"voice_call_hangon_icon"]
self.answerButton = [[CircleButton alloc] initWithImage:[[AssetImages voiceCallHangonIcon] image]
borderColor:answerButtonBorderColor];
self.answerButton.defaultBackgroundColor = ThemeService.shared.theme.backgroundColor;
self.answerButton.tintColor = answerButtonBorderColor;
Expand All @@ -103,7 +103,7 @@ - (instancetype)initWithCallerAvatar:(NSString *)mxcAvatarURI

UIColor *rejectButtonBorderColor = ThemeService.shared.theme.warningColor;

self.rejectButton = [[CircleButton alloc] initWithImage:[UIImage imageNamed:@"voice_call_hangup_icon"]
self.rejectButton = [[CircleButton alloc] initWithImage:[[AssetImages voiceCallHangupIcon] image]
borderColor:rejectButtonBorderColor];
self.rejectButton.defaultBackgroundColor = ThemeService.shared.theme.backgroundColor;
self.rejectButton.tintColor = rejectButtonBorderColor;
Expand Down
4 changes: 2 additions & 2 deletions Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -816,11 +816,11 @@ - (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame
UIImage *chevron;
if (shrinkedSectionsBitMask & sectionBitwise)
{
chevron = [UIImage imageNamed:@"disclosure_icon"];
chevron = [[AssetImages disclosureIcon] image];
}
else
{
chevron = [UIImage imageNamed:@"shrink_icon"];
chevron = [[AssetImages shrinkIcon] image];
}
UIImageView *chevronView = [[UIImageView alloc] initWithImage:chevron];
chevronView.tintColor = ThemeService.shared.theme.textSecondaryColor;
Expand Down
14 changes: 7 additions & 7 deletions Riot/Modules/Common/Recents/RecentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView tra
}];
directChatAction.backgroundColor = actionBackgroundColor;

UIImage *directChatImage = [UIImage imageNamed:@"room_action_direct_chat"];
UIImage *directChatImage = [[AssetImages roomActionDirectChat] image];
directChatImage = [directChatImage vc_tintedImageUsingColor:isDirect ? selectedColor : unselectedColor];
directChatAction.image = [directChatImage vc_notRenderedImage];

Expand All @@ -1120,13 +1120,13 @@ - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView tra
muteAction.backgroundColor = actionBackgroundColor;

UIImage *notificationImage;
if([BuildSettings showNotificationsV2])
if([BuildSettings showNotificationsV2] && isMuted)
{
notificationImage = isMuted ? [UIImage imageNamed:@"room_action_notification_muted"] : [UIImage imageNamed:@"room_action_notification"];
notificationImage = [[AssetImages roomActionNotificationMuted] image];
}
else
{
notificationImage = [UIImage imageNamed:@"room_action_notification"];
notificationImage = [[AssetImages roomActionNotification] image];
}

notificationImage = [notificationImage vc_tintedImageUsingColor:isMuted ? unselectedColor : selectedColor];
Expand Down Expand Up @@ -1157,7 +1157,7 @@ - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView tra
}];
favouriteAction.backgroundColor = actionBackgroundColor;

UIImage *favouriteImage = [UIImage imageNamed:@"room_action_favourite"];
UIImage *favouriteImage = [[AssetImages roomActionFavourite] image];
favouriteImage = [favouriteImage vc_tintedImageUsingColor:isFavourite ? selectedColor : unselectedColor];
favouriteAction.image = [favouriteImage vc_notRenderedImage];

Expand All @@ -1174,7 +1174,7 @@ - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView tra
}];
priorityAction.backgroundColor = actionBackgroundColor;

UIImage *priorityImage = isInLowPriority ? [UIImage imageNamed:@"room_action_priority_high"] : [UIImage imageNamed:@"room_action_priority_low"];
UIImage *priorityImage = isInLowPriority ? [[AssetImages roomActionPriorityHigh] image] : [[AssetImages roomActionPriorityLow] image];
priorityImage = [priorityImage vc_tintedImageUsingColor:unselectedColor];
priorityAction.image = [priorityImage vc_notRenderedImage];

Expand All @@ -1188,7 +1188,7 @@ - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView tra
}];
leaveAction.backgroundColor = actionBackgroundColor;

UIImage *leaveImage = [UIImage imageNamed:@"room_action_leave"];
UIImage *leaveImage = [[AssetImages roomActionLeave] image];
leaveImage = [leaveImage vc_tintedImageUsingColor:unselectedColor];
leaveAction.image = [leaveImage vc_notRenderedImage];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ - (void)addAddParticipantButton

addParticipantButtonImageView.backgroundColor = [UIColor clearColor];
addParticipantButtonImageView.contentMode = UIViewContentModeCenter;
addParticipantButtonImageView.image = [UIImage imageNamed:@"add_group_participant"];
addParticipantButtonImageView.image = [[AssetImages addGroupParticipant] image];

CGFloat side = 78.0f;
NSLayoutConstraint* widthConstraint = [NSLayoutConstraint constraintWithItem:addParticipantButtonImageView
Expand Down Expand Up @@ -534,7 +534,7 @@ - (void)onAddParticipantButtonPressed
contactsDataSource.displaySearchInputInContactsList = YES;
contactsDataSource.forceMatrixIdInDisplayName = YES;
// Add a plus icon to the contact cell in the contacts picker, in order to make it more understandable for the end user.
contactsDataSource.contactCellAccessoryImage = [[UIImage imageNamed:@"plus_icon"] vc_tintedImageUsingColor:ThemeService.shared.theme.textPrimaryColor];
contactsDataSource.contactCellAccessoryImage = [[[AssetImages plusIcon] image] vc_tintedImageUsingColor:ThemeService.shared.theme.textPrimaryColor];

// List all the participants matrix user id to ignore them during the contacts search.
for (Contact *contact in actualParticipants)
Expand Down
6 changes: 3 additions & 3 deletions Riot/Modules/Contacts/DataSources/ContactsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -840,11 +840,11 @@ - (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame
UIImage *chevron;
if (shrinkedSectionsBitMask & sectionBitwise)
{
chevron = [UIImage imageNamed:@"disclosure_icon"];
chevron = [[AssetImages disclosureIcon] image];
}
else
{
chevron = [UIImage imageNamed:@"shrink_icon"];
chevron = [[AssetImages shrinkIcon] image];
}
UIImageView *chevronView = [[UIImageView alloc] initWithImage:chevron];
chevronView.tintColor = ThemeService.shared.theme.textSecondaryColor;
Expand Down Expand Up @@ -889,7 +889,7 @@ - (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame
checkboxLabel.textColor = ThemeService.shared.theme.textPrimaryColor;

// Set the right value of the tick box
localContactsCheckbox.image = hideNonMatrixEnabledContacts ? [UIImage imageNamed:@"selection_tick"] : [UIImage imageNamed:@"selection_untick"];
localContactsCheckbox.image = hideNonMatrixEnabledContacts ? [[AssetImages selectionTick] image] : [[AssetImages selectionUntick] image];
localContactsCheckbox.tintColor = ThemeService.shared.theme.tintColor;

// Add the check box container
Expand Down
Loading

0 comments on commit 086d053

Please sign in to comment.