Skip to content
This repository was archived by the owner on Jun 3, 2022. It is now read-only.

Commit 2929129

Browse files
author
Andrés
authored
Merge pull request #65 from material-foundation/text_input
Adds a control for text input
2 parents f559036 + 8223558 commit 2929129

16 files changed

+204
-52
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![remixer](https://cdn.rawgit.com/material-foundation/material-remixer/master/docs/assets/lockup_remixer_icon_horizontal_dark_small.svg)
22

3-
Remixer helps teams use and refine design specs by providing an abstraction for these values that is accessible and configurable from both inside and outside the app itself.
3+
Remixer helps teams use and refine design specs by providing an abstraction for these values that is accessible and configurable from both inside and outside the app itself.
44

55
This SDK for iOS is currently in development.
66

@@ -73,13 +73,13 @@ Note that we currently support only RMXStorageModeLocal as RMXStorageModeCloud i
7373

7474
- (BOOL)application:(UIApplication *)application
7575
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
76-
76+
7777
// Create the window
7878
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
7979

8080
// Start Remixer
8181
[RMXRemixer startInMode:RMXStorageModeLocal];
82-
82+
8383
// Create the root view controller and set it in the window
8484
self.window.rootViewController = [[UIViewController alloc] init];
8585
[self.window makeKeyAndVisible];
@@ -105,7 +105,7 @@ Now you can add Remixer variables in your view controller classes as follows:
105105
_box = [[UIView alloc] initWithFrame:CGRectMake(50, 150, 80, 80)];
106106
_box.backgroundColor = [UIColor redColor];
107107
[self.view addSubview:_box];
108-
108+
109109
// Add a color variable to control the background color.
110110
// Note: You can set possibleValues to limit it to certain colors.
111111
[RMXColorVariable

examples/objc/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ PODS:
2323
- GoogleToolboxForMac/Defines (2.1.0)
2424
- GoogleToolboxForMac/NSData+zlib (2.1.0):
2525
- GoogleToolboxForMac/Defines (= 2.1.0)
26-
- Remixer/Core (1.0.0)
27-
- Remixer/Firebase (1.0.0):
28-
- Firebase/Core
29-
- Firebase/Database
26+
- Remixer/Core (0.5.2)
27+
- Remixer/Firebase (0.5.2):
28+
- Firebase/Core (~> 3.8)
29+
- Firebase/Database (~> 3.1)
3030
- Remixer/Core
3131

3232
DEPENDENCIES:
@@ -45,7 +45,7 @@ SPEC CHECKSUMS:
4545
GoogleInterchangeUtilities: d5bc4d88d5b661ab72f9d70c58d02ca8c27ad1f7
4646
GoogleSymbolUtilities: 631ee17048aa5e9ab133470d768ea997a5ef9b96
4747
GoogleToolboxForMac: 2b2596cbb7186865e98cadf2b1e262d851c2b168
48-
Remixer: 6083bf76ba904c8e7dfa38acb2834cdad4b49838
48+
Remixer: d358089aa00e0b780ae0710a2b356b0c7d36016a
4949

5050
PODFILE CHECKSUM: d1a9444e2abc793509b33eccd75ed4aaad6d17bf
5151

examples/objc/RemixerExample/ColorDemoViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ - (void)viewDidLoad {
3838
[RMXColorVariable
3939
colorVariableWithKey:@"boxBgColor"
4040
defaultValue:[UIColor redColor]
41-
possibleValues:@[[UIColor redColor], [UIColor blueColor], [UIColor greenColor]]
41+
possibleValues:@[ [UIColor redColor], [UIColor blueColor], [UIColor greenColor] ]
4242
updateBlock:^(RMXColorVariable *_Nonnull variable, UIColor *selectedValue) {
4343
_box.backgroundColor = selectedValue;
4444
}];

examples/objc/RemixerExample/FontViewController.m

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,40 @@ - (void)viewDidLoad {
3030
[super viewDidLoad];
3131
self.view.backgroundColor = [UIColor whiteColor];
3232

33-
_fontLabel =
34-
[[UILabel alloc] initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.view.bounds), 40)];
33+
_fontLabel = [[UILabel alloc] initWithFrame:CGRectZero];
34+
_fontLabel.numberOfLines = 0;
3535
_fontLabel.textAlignment = NSTextAlignmentCenter;
3636
[self.view addSubview:_fontLabel];
3737

38+
[RMXStringVariable stringVariableWithKey:@"labelText"
39+
defaultValue:@"This is a customizable label"
40+
updateBlock:^(RMXStringVariable *variable, NSString *selectedValue) {
41+
_fontLabel.text = selectedValue;
42+
[self.view setNeedsLayout];
43+
}];
44+
3845
NSArray<NSString *> *fontNames = @[
3946
@"System", @"AvenirNext-Bold", @"Baskerville-SemiBold", @"Courier",
4047
@"Futura-CondensedExtraBold", @"Helvetica-Light", @"SnellRoundhand"
4148
];
4249
[RMXStringVariable
43-
stringVariableWithKey:@"font"
50+
stringVariableWithKey:@"labelFont"
4451
defaultValue:fontNames[1]
4552
possibleValues:fontNames
46-
updateBlock:^(RMXStringVariable *variable, NSString *selectedValue) {
47-
NSString *fontName = selectedValue;
48-
_fontLabel.text = fontName;
53+
updateBlock:^(RMXStringVariable *variable, NSString *selectedFontName) {
4954
_fontLabel.font =
50-
[UIFont fontWithName:fontName size:[UIFont labelFontSize]];
55+
[UIFont fontWithName:selectedFontName size:_fontLabel.font.pointSize];
56+
[self.view setNeedsLayout];
5157
}];
5258
}
5359

60+
- (void)viewWillLayoutSubviews {
61+
[super viewWillLayoutSubviews];
62+
63+
CGSize labelSize = [_fontLabel sizeThatFits:CGRectInset(self.view.bounds, 20, 100).size];
64+
_fontLabel.frame = CGRectMake(20, 100, self.view.bounds.size.width - 40, labelSize.height);
65+
}
66+
5467
- (void)viewWillDisappear:(BOOL)animated {
5568
[super viewWillDisappear:animated];
5669
[RMXRemixer removeAllVariables];

examples/objc/RemixerExample/SpinningBoxViewController.m

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,22 @@ - (void)viewDidLoad {
6161

6262
// Set box2 animation to be twice as fast.
6363
presentationLayer = _box2.layer.presentationLayer;
64-
angle =
65-
[[presentationLayer valueForKeyPath:@"transform.rotation.z"] floatValue];
64+
angle = [[presentationLayer valueForKeyPath:@"transform.rotation.z"] floatValue];
6665
animation.fromValue = [NSNumber numberWithFloat:angle];
6766
animation.toValue = [NSNumber numberWithFloat:angle + M_PI * 2.0];
6867
animation.duration = MAX(2.0 - (selectedValue * 2), 0.1);
6968
[_box2.layer addAnimation:animation forKey:@"spinning"];
7069
}];
7170

72-
[RMXBooleanVariable
73-
booleanVariableWithKey:@"slowAnimations"
74-
defaultValue:NO
75-
updateBlock:^(RMXBooleanVariable *variable, BOOL selectedValue) {
76-
CALayer *layer = self.view.layer;
77-
layer.timeOffset =
78-
[layer convertTime:CACurrentMediaTime() fromLayer:nil];
79-
layer.beginTime = CACurrentMediaTime();
80-
layer.speed = selectedValue ? 0.2 : 1;
81-
}];
71+
[RMXBooleanVariable booleanVariableWithKey:@"slowAnimations"
72+
defaultValue:NO
73+
updateBlock:^(RMXBooleanVariable *variable, BOOL selectedValue) {
74+
CALayer *layer = self.view.layer;
75+
layer.timeOffset =
76+
[layer convertTime:CACurrentMediaTime() fromLayer:nil];
77+
layer.beginTime = CACurrentMediaTime();
78+
layer.speed = selectedValue ? 0.2 : 1;
79+
}];
8280
}
8381

8482
- (void)viewWillDisappear:(BOOL)animated {

src/core/RMXRemixer.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ + (void)start {
9191
if (instance.storageMode == RMXStorageModeLocal) {
9292
instance.storage = [[RMXLocalStorageController alloc] init];
9393
} else {
94-
#ifdef REMIXER_CLOUD_FIREBASE
94+
#ifdef REMIXER_CLOUD_FIREBASE
9595
instance.storage = [[RMXFirebaseStorageController alloc] init];
96-
#else
96+
#else
9797
instance.storage = [[RMXLocalStorageController alloc] init];
98-
// TODO(chuga): Print out a warning.
99-
#endif
98+
// TODO(chuga): Print out a warning.
99+
#endif
100100
}
101101
[instance.storage setup];
102102
[instance.storage startObservingUpdates];

src/core/UI/RMXOverlayViewController.m

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323
#import "RMXCellButton.h"
2424
#import "RMXCellColorList.h"
25+
#import "RMXCellColorPicker.h"
2526
#import "RMXCellSegmented.h"
2627
#import "RMXCellSlider.h"
2728
#import "RMXCellStepper.h"
2829
#import "RMXCellSwitch.h"
29-
#import "RMXCellColorPicker.h"
30+
#import "RMXCellTextInput.h"
3031
#import "RMXCellTextPicker.h"
3132
#import "RMXOverlayNavigationBar.h"
3233
#import "RMXOverlayView.h"
@@ -40,7 +41,8 @@
4041
@interface RMXOverlayViewController () <UITableViewDataSource,
4142
UITableViewDelegate,
4243
UIGestureRecognizerDelegate,
43-
RMXOverlayViewDelegate>
44+
RMXOverlayViewDelegate,
45+
RMXCellDelegate>
4446
@property(nonatomic, strong) RMXOverlayView *view;
4547
@end
4648

@@ -64,6 +66,7 @@ - (void)viewDidLoad {
6466

6567
self.view.tableView.dataSource = self;
6668
self.view.tableView.delegate = self;
69+
self.view.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
6770

6871
[self.view.tableView registerClass:[RMXCellButton class]
6972
forCellReuseIdentifier:NSStringFromClass([RMXCellButton class])];
@@ -81,6 +84,8 @@ - (void)viewDidLoad {
8184
forCellReuseIdentifier:NSStringFromClass([RMXCellSwitch class])];
8285
[self.view.tableView registerClass:[RMXCellTextPicker class]
8386
forCellReuseIdentifier:NSStringFromClass([RMXCellTextPicker class])];
87+
[self.view.tableView registerClass:[RMXCellTextInput class]
88+
forCellReuseIdentifier:NSStringFromClass([RMXCellTextInput class])];
8489

8590
UINavigationItem *item = self.view.navigationBar.topItem;
8691
[(UIButton *)item.leftBarButtonItem.customView addTarget:self
@@ -200,10 +205,11 @@ - (void)maximizePanel {
200205
}
201206

202207
- (void)dismissOverlay:(id)sender {
203-
[self dismissOptionsViewWithCompletion:nil];
208+
[self dismissOverlayWithCompletion:nil];
204209
}
205210

206-
- (void)dismissOptionsViewWithCompletion:(void (^)(BOOL finished))completion {
211+
- (void)dismissOverlayWithCompletion:(void (^)(BOOL finished))completion {
212+
[self.view endEditing:YES];
207213
[UIView animateWithDuration:0.2
208214
animations:^{
209215
[self.view hidePanel];
@@ -226,7 +232,7 @@ - (void)sendEmailInvite:(id)sender {
226232
[RMXRemixer sendEmailInvite];
227233
}
228234

229-
#pragma mark - <UITableViewDataSource>
235+
#pragma mark - UITableViewDataSource
230236

231237
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
232238
return [_content count];
@@ -238,15 +244,18 @@ - (UITableViewCell *)tableView:(UITableView *)tableView
238244
NSString *identifier = [self cellIdentifierForVariable:variable];
239245
RMXCell *cell = (RMXCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
240246
cell.variable = variable;
247+
cell.delegate = self;
241248
return cell;
242249
}
243250

251+
#pragma mark - UITableViewDelegate
252+
244253
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
245254
RMXVariable *variable = _content[indexPath.row];
246255
return [[self cellClassForVariable:variable] cellHeight];
247256
}
248257

249-
#pragma mark - <RMXOverlayViewDelegate>
258+
#pragma mark - RMXOverlayViewDelegate
250259

251260
- (void)touchStartedAtPoint:(CGPoint)point withEvent:(UIEvent *)event {
252261
// No-op.
@@ -256,6 +265,12 @@ - (BOOL)shouldCapturePointOutsidePanel:(CGPoint)point {
256265
return self.presentedViewController != nil;
257266
}
258267

268+
#pragma mark - RMXCellDelegate
269+
270+
- (void)cellRequestedFullScreenOverlay:(RMXCell *)cell {
271+
[self maximizePanel];
272+
}
273+
259274
#pragma mark - Private
260275

261276
- (Class)cellClassForVariable:(RMXVariable *)variable {
@@ -275,6 +290,8 @@ - (Class)cellClassForVariable:(RMXVariable *)variable {
275290
return [RMXCellSwitch class];
276291
} else if (variable.controlType == RMXControlTypeTextPicker) {
277292
return [RMXCellTextPicker class];
293+
} else if (variable.controlType == RMXControlTypeTextInput) {
294+
return [RMXCellTextInput class];
278295
}
279296
return nil;
280297
}

src/core/UI/cells/RMXCell.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,24 @@
2121

2222
NS_ASSUME_NONNULL_BEGIN
2323

24+
@class RMXCell;
25+
2426
/** Minimal height for the cell. */
2527
extern const CGFloat RMXCellHeightMinimal;
2628

2729
/** Larger height for the cell. */
2830
extern const CGFloat RMXCellHeightLarge;
2931

32+
@protocol RMXCellDelegate <NSObject>
33+
34+
/**
35+
Called by the cell when it requires the overlay to go full screen.
36+
One example use case is when the keyboard appears.
37+
*/
38+
- (void)cellRequestedFullScreenOverlay:(RMXCell *)cell;
39+
40+
@end
41+
3042
/**
3143
The RMXCell class provides table view cell that should be subclassed for specific Variable
3244
model types.
@@ -39,6 +51,9 @@ extern const CGFloat RMXCellHeightLarge;
3951
/** The Variable this cell is controlling. */
4052
@property(nonatomic, weak) RMXVariable *variable;
4153

54+
/** The delegate for this cell. */
55+
@property(nonatomic, weak) id<RMXCellDelegate> delegate;
56+
4257
/** The height of this cell. Subclasses should override. */
4358
+ (CGFloat)cellHeight;
4459

src/core/UI/cells/RMXCellColorPicker.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ - (void)layoutSubviews {
9191
[_button sizeToFit];
9292
_button.frame =
9393
CGRectMake(CGRectGetWidth(self.controlViewWrapper.frame) - CGRectGetWidth(_button.frame),
94-
kButtonTopOffset,
95-
CGRectGetWidth(_button.frame),
96-
CGRectGetHeight(_button.frame));
94+
kButtonTopOffset, CGRectGetWidth(_button.frame), CGRectGetHeight(_button.frame));
9795
}
9896

9997
- (void)prepareForReuse {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2016-present Google Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#import "RMXCell.h"
18+
19+
#import "RMXStringVariable.h"
20+
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
/** Provides a table view cell that has a text field. */
24+
@interface RMXCellTextInput : RMXCell
25+
26+
@property(nonatomic, weak) RMXStringVariable *variable;
27+
28+
@end
29+
30+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)