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

Bug/VENTokenView fixes #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -26,6 +26,7 @@
NSMutableArray * _contacts;
NSMutableArray * _selectedContacts;
NSMutableArray * _contactsToExclude;
NSMutableArray * _selectedNames;

NSString * _filterByName;
id _internetConnectionObserver;
Expand All @@ -36,9 +37,8 @@
@property (nonatomic, readwrite) NSString * rightBarButtonActionTitle;
@property (nonatomic, readwrite) NSArray * (^overrideContacts)();

@property (weak, nonatomic) IBOutlet VENTokenField * _tokenField;
@property (strong, nonatomic) NSMutableArray * names;
@property (weak, nonatomic) IBOutlet UIView * _tokenView;
@property (weak, nonatomic) IBOutlet VENTokenField * tokenField;
@property (weak, nonatomic) IBOutlet UIView * tokenView;
@property (weak, nonatomic) IBOutlet UITextField * groupNameTextField;
@property (weak, nonatomic) IBOutlet UIView * groupNameView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#define bContactsSection 0
#define bSectionCount 1
#define bMaxTokenHeight 104

@interface BFriendsListViewController ()

Expand All @@ -25,15 +26,14 @@ @implementation BFriendsListViewController
@synthesize tableView;
@synthesize usersToInvite;
@synthesize rightBarButtonActionTitle;
@synthesize _tokenField;
@synthesize _tokenView;
@synthesize tokenField;
@synthesize tokenView;
@synthesize groupNameView;
@synthesize groupNameTextField;
@synthesize maximumSelectedUsers;

// If we create it with a thread then we look at who is in the thread and make sure they don't come up on the lists
// If we are creating a new thread then we don't mind

// If we are creating a thread we want to have the group name field
// If we are adding users we never want to show this field
-(instancetype) initWithUsersToExclude: (NSArray<PUser> *) users {
if ((self = [self init])) {
self.title = [NSBundle t:bPickFriends];
Expand All @@ -46,9 +46,10 @@ -(instancetype) init {
self = [super initWithNibName:@"BFriendsListViewController" bundle:[NSBundle chatUIBundle]];
if (self) {
self.title = [NSBundle t:bPickFriends];
_selectedContacts = [NSMutableArray new];
_contacts = [NSMutableArray new];
_contactsToExclude = [NSMutableArray new];
_selectedContacts = [NSMutableArray new];
_selectedNames = [NSMutableArray new];
}
return self;
}
Expand All @@ -65,17 +66,17 @@ - (void)viewDidLoad {
// Takes into account the status and navigation bar
self.edgesForExtendedLayout = UIRectEdgeNone;

self.names = [NSMutableArray array];
_tokenField.delegate = self;
_tokenField.dataSource = self;
_tokenField.placeholderText = [NSBundle t:bEnterNamesHere];
_tokenField.toLabelText = [NSBundle t:bTo];
_tokenField.userInteractionEnabled = YES;
tokenField.delegate = self;
tokenField.dataSource = self;
tokenField.placeholderText = [NSBundle t:bEnterNamesHere];
tokenField.toLabelText = [NSBundle t:bTo];
tokenField.userInteractionEnabled = YES;
tokenField.maxHeight = bMaxTokenHeight;

[_tokenField setColorScheme:[UIColor colorWithRed:61/255.0f green:149/255.0f blue:206/255.0f alpha:1.0f]];
[tokenField setColorScheme:[UIColor colorWithRed:61/255.0f green:149/255.0f blue:206/255.0f alpha:1.0f]];

_tokenView.layer.borderWidth = 0.5;
_tokenView.layer.borderColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0].CGColor;
tokenView.layer.borderWidth = 0.5;
tokenView.layer.borderColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0].CGColor;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:Nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:Nil];
Expand Down Expand Up @@ -183,7 +184,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(

BUserCell * cell = [tableView_ dequeueReusableCellWithIdentifier:bUserCellIdentifier];


id<PUser> user;
if (indexPath.section == bContactsSection) {
user = _contacts[indexPath.row];
Expand All @@ -207,7 +207,7 @@ - (void)tableView:(UITableView *)tableView_ didSelectRowAtIndexPath:(NSIndexPath
[tableView_ deselectRowAtIndexPath:indexPath animated:YES];

[UIView animateWithDuration:0.2 animations:^{
_tokenView.keepHeight.equal = _tokenField.bounds.size.height;
tokenView.keepHeight.equal = tokenField.bounds.size.height;
}];

[self reloadData];
Expand All @@ -219,9 +219,8 @@ - (void)tokenField:(VENTokenField *)tokenField didChangeText:(NSString *)text {
if (text.length) {

[UIView animateWithDuration:0.2 animations:^{
_tokenView.keepHeight.equal = _tokenField.bounds.size.height;
tokenView.keepHeight.equal = tokenField.bounds.size.height;
}];

}
_filterByName = text;
[self reloadData];
Expand All @@ -230,64 +229,68 @@ - (void)tokenField:(VENTokenField *)tokenField didChangeText:(NSString *)text {
// This is when we press enter in the text field
- (void)tokenField:(VENTokenField *)tokenField didEnterText:(NSString *)text {

[_tokenField reloadData];
[tokenField reloadData];
[self reloadData];

[_tokenField resignFirstResponder];
[tokenField resignFirstResponder];
}

// This is when we delete a token
- (void)tokenField:(VENTokenField *)tokenField didDeleteTokenAtIndex:(NSUInteger)index {

[self deselectUserWithName:[self.names objectAtIndex:index]];
[self deselectUser:[_selectedContacts objectAtIndex: index]];

[UIView animateWithDuration:0.2 animations:^{
_tokenView.keepHeight.equal = _tokenField.bounds.size.height;
tokenView.keepHeight.equal = tokenField.bounds.size.height;
}];
}

#pragma mark - VENTokenFieldDataSource

- (NSString *)tokenField:(VENTokenField *)tokenField titleForTokenAtIndex:(NSUInteger)index {
return self.names[index];
return _selectedNames[index];
}

- (NSUInteger)numberOfTokensInTokenField:(VENTokenField *)tokenField {
return self.names.count;
return _selectedNames.count;
}

- (void) selectUser: (id<PUser>) user {

if(_selectedContacts.count < maximumSelectedUsers || maximumSelectedUsers <= 0) {
[_selectedContacts addObject:user];

[self.names addObject:user.name];
[_selectedNames addObject:user.name];

_filterByName = Nil;
[_tokenField reloadData];
[tokenField reloadData];

[self setGroupNameHidden:_selectedContacts.count < 2 || _contactsToExclude.count > 0 duration:0.4];
// We never want to show this if we are adding users (and therefore have users to exclude)
[self setGroupNameHidden:_selectedContacts.count < 2 || _contactsToExclude.count duration:0.4];

[self reloadData];
}

}

// TODO: This will fail if there are two users with the same name...
- (void) deselectUserWithName: (NSString *) name {
- (void) deselectUser: (id<PUser>) user {

// Get the user we are removing
for (id<PUser> user in _selectedContacts) {
if ([name caseInsensitiveCompare:user.name] == NSOrderedSame) {
[_selectedContacts removeObject:user];
break;
if ([_selectedContacts containsObject:user]) {

// We want to then remove the same index
NSInteger index = [_selectedContacts indexOfObject:user];

if ([_selectedNames[index] isEqualToString:user.name]) {
[_selectedNames removeObjectAtIndex:index];
[_selectedContacts removeObjectAtIndex:index];
}
else {
NSLog(@"Name synchronisation error");
}
}

[self.names removeObject:name];
[_tokenField reloadData];
[tokenField reloadData];

[self setGroupNameHidden:_selectedContacts.count + _contactsToExclude.count < 2 duration:0.4];
// We never want to show this if we are adding users (and therefore have users to exclude)
[self setGroupNameHidden:_selectedContacts.count < 2 || _contactsToExclude.count duration:0.4];

[self reloadData];
}
Expand Down Expand Up @@ -340,7 +343,6 @@ -(void) setSelectedUsers: (NSArray *) users {
[self reloadData];
}


#pragma keyboard notifications

-(void) keyboardWillShow: (NSNotification *) notification {
Expand All @@ -354,7 +356,8 @@ -(void) keyboardWillShow: (NSNotification *) notification {
NSNumber *curve = [notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];

// Set the new constraints
tableView.keepBottomInset.equal = keyboardBoundsConverted.size.height;
[self setTableViewBottomContentInset:keyboardBoundsConverted.size.height];

[self.view setNeedsUpdateConstraints];

// Animate using this style because for some reason using blocks doesn't give a smooth animation
Expand All @@ -370,11 +373,17 @@ -(void) keyboardWillShow: (NSNotification *) notification {

-(void) keyboardWillHide: (NSNotification *) notification {

// Reduced code as there were slight issues with teh table reloading
tableView.keepBottomInset.equal = 0;
// Fix - to ensure the tableView can scroll above the keyboard
[self setTableViewBottomContentInset:0];
[self.view setNeedsUpdateConstraints];
}

-(void) setTableViewBottomContentInset: (float) inset {
UIEdgeInsets insets = tableView.contentInset;
insets.bottom = inset;
tableView.contentInset = insets;
}

-(void) dismissView {
[self dismissViewControllerAnimated:YES completion:Nil];
}
Expand All @@ -385,6 +394,4 @@ - (void)updateButtonStatusForInternetConnection {
self.navigationItem.rightBarButtonItem.enabled = connected;
}



@end
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ - (void)tableView:(UITableView *)tableView_ didSelectRowAtIndexPath:(NSIndexPath
// Use initWithThread here to make sure we don't show any users already in the thread
// Show the friends view controller
BFriendsListViewController * flvc = [[BInterfaceManager sharedManager].a friendsViewControllerWithUsersToExclude:_thread.users.allObjects];

flvc.rightBarButtonActionTitle = [NSBundle t:bAdd];

// The friends view controller will give us a list of users to invite
Expand Down
14 changes: 5 additions & 9 deletions ChatSDKUI/Interface/BFriendsListViewController.xib
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2657" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="BFriendsListViewController">
<connections>
<outlet property="_tokenField" destination="UkR-FR-EHR" id="d3f-bH-zGs"/>
<outlet property="_tokenView" destination="Ok8-lm-Uad" id="DPB-kg-qqK"/>
<outlet property="groupNameTextField" destination="Lfx-uF-C6f" id="vWr-Ix-nxW"/>
<outlet property="groupNameView" destination="281-dx-DD4" id="Zd7-ch-Jrc"/>
<outlet property="tableView" destination="3eB-zr-9l2" id="3Uy-K9-6ll"/>
<outlet property="tokenField" destination="UkR-FR-EHR" id="HoG-Ed-BS5"/>
<outlet property="tokenView" destination="Ok8-lm-Uad" id="cbN-Eo-49G"/>
<outlet property="view" destination="1" id="3"/>
</connections>
</placeholder>
Expand Down Expand Up @@ -61,6 +61,7 @@
<constraint firstItem="UkR-FR-EHR" firstAttribute="leading" secondItem="Ok8-lm-Uad" secondAttribute="leading" id="PQZ-qY-97C"/>
<constraint firstAttribute="trailing" secondItem="UkR-FR-EHR" secondAttribute="trailing" id="Qz4-km-9Uc"/>
<constraint firstAttribute="height" priority="750" constant="44" id="ZqI-ur-oOm"/>
<constraint firstAttribute="bottom" secondItem="UkR-FR-EHR" secondAttribute="bottom" id="t5i-Xs-NBR"/>
</constraints>
</view>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="none" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="3eB-zr-9l2">
Expand Down Expand Up @@ -88,9 +89,4 @@
<point key="canvasLocation" x="-100.5" y="-91.5"/>
</view>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4_7.fullscreen"/>
</simulatedMetricsContainer>
</document>