motion-swipe 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adc9623ea0b8146e434ebc51f33d17baa398723b
4
- data.tar.gz: 1c93ae54f0cffa17bba3b2fcfee4339f5290cf06
3
+ metadata.gz: 9f380f1c29d88c3edfbb39e99aa608ef9c85b560
4
+ data.tar.gz: 8c4d6f574549a9940828de2ca4224197821d94d2
5
5
  SHA512:
6
- metadata.gz: fabdfbb3e404a98c5633d44dcc509e35f9113c98c7589bcfbdc058e958be8634c3d732ea54196cb3373861f343cf24d95ce4e6a795b99c314a4ae6673116f42f
7
- data.tar.gz: f08ec5320a01bf6178e69973035417c2b42128668fdc2a1785b0a6ff2c0f0ed108f7697d83b0d69947cc3cf004b5221e087e512b4f2f7d8741e9f26239b406a6
6
+ metadata.gz: ed88c917fcfe8fba11163d6f797b2b256055663f884f808bf6b943bd94e6f014ac9ae5c3f8f4edc3ab0037bc2e0b2aad0b4b7edaef234d37794d96e3d6b22858
7
+ data.tar.gz: 24c25683a42ec997c65f84abee86db3e110aeec8f92139f957815627c234e5cfb05f13ffe570d280c4aa5044bb12cbb92de8334a6f7c2a0686faa8bef1f0a3ac
data/README.md CHANGED
@@ -1,4 +1,54 @@
1
1
  Motion-Swipe for RubyMotion
2
2
  ====================
3
+ ![alt tag](http://imgur.com/4bYw12e.gif)
4
+
5
+ Trying to add a Tinder-like swipe gem for RubyMotion. Not really production ready but useable. PRs for fixes, refactors and features accepted! This is also my first gem - advice/help is welcome.
6
+
7
+ This is a wrapper around Richard Kim's TinderSimpleSwipeCards written in obj-c. He does an excellent job detailing how it all works, so that you customize it easily. Some of that got erased when I was making this, so see his source: https://github.com/cwRichardKim/TinderSimpleSwipeCards
8
+
9
+ __create a draggable view background__
10
+ ``` ruby
11
+ @draggable = MotionSwipe.build({
12
+ frame: CGRectMake(0, 0, self.view.frame.width, self.view.frame.height),
13
+ delegate: self # Needed if you want to call method of a class with your button
14
+ })
15
+ ```
16
+
17
+ __adjust the draggable view's height and width__
18
+ ``` ruby
19
+ @draggable.setCardWithHeight(@height, withWidth: width)
20
+ ```
21
+
22
+ __create a new draggable view, and add it to the draggable view background__
23
+ ``` ruby
24
+ new_card = @draggable.createDraggableView
25
+ @draggable.addCard(new_card)
26
+ ```
27
+
28
+ __now just append views, buttons, or whatever to that draggable view__
29
+ ``` ruby
30
+ # you can assign an id to the card for identification
31
+ new_card.cardId = card_id
32
+ ```
33
+
34
+ __make sure to load the cards you added into the draggable view background__
35
+ ``` ruby
36
+ # this method returns the number of cards
37
+ count = @draggable.loadCards()
38
+ ```
39
+
40
+ __methods are available to swipe cards left or right without a gesture__
41
+ ``` ruby
42
+ @draggable.swipeRight()
43
+ @draggable.swipeLeft()
44
+ ```
45
+
46
+ __NSUserDefaults are used to track the current card, previously swiped card, and previous swipe direction__
47
+ ```
48
+ @defaults = NSUserDefaults.standardUserDefaults
49
+ @defaults["cardCurrent"]
50
+ @defaults["cardSwiped"]
51
+ @defaults["cardSwipedDirection"]
52
+ ```
53
+
3
54
 
4
- Trying to add a Tinder-like swipe gem for RubyMotion.
@@ -6,7 +6,7 @@ Motion::Project::App.setup do |app|
6
6
  Dir.glob(File.join(File.dirname(__FILE__), 'motion-swipe/*.rb')).each do |file|
7
7
  app.files.unshift(file)
8
8
  end
9
+
9
10
  app.vendor_project(File.expand_path(File.join(File.dirname(__FILE__), '../vendor/motion-swipe')), :static, cflags: "-fobjc-arc")
10
- app.frameworks += ['CoreData']
11
11
 
12
12
  end
@@ -3,11 +3,10 @@ module MotionSwipe
3
3
  module_function
4
4
 
5
5
  def build(args)
6
- # @allCards = args[:cards] || "blahblah"
7
- puts args
8
- @exampleCardLabels = args[:example_card_labels] || ["1", "second", "3rd", "last"]
9
- @allCards = args[:all_cards] || ["1", "second", "3rd", "last"]
10
- @title = args[:title] || nil
6
+
7
+ # @exampleCardLabels = args[:example_card_labels] || ["1", "second", "3rd", "last"]
8
+ # @allCards = args[:all_cards] || ["1", "second", "3rd", "last"]
9
+ # @title = args[:title] || nil
11
10
  @frame = args[:frame] || @delegate.view.frame
12
11
 
13
12
  draggable = DraggableViewBackground.alloc.initWithFrame(@frame)
@@ -49,17 +49,12 @@
49
49
  @property (nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled;
50
50
  @property (nonatomic)CGPoint originalPoint;
51
51
  @property (nonatomic,strong)OverlayView* overlayView;
52
- @property (nonatomic,strong)UILabel* transName; //%%% a placeholder for any card-specific information
53
- @property (nonatomic,strong)UILabel* amount;
54
- @property (nonatomic,strong)UILabel* date;
55
- @property (nonatomic,strong)UILabel* category;
52
+
56
53
  @property (nonatomic,strong)UILabel* swipeType;
57
- @property (retain,nonatomic)NSString* transactionId;
58
- // @property (nonatomic,strong)NSString transactionId;
59
- // @property (nonatomic,strong)BOOL* swiped;
60
- // @property (nonatomic,strong)BOOL* business;
54
+ @property (retain,nonatomic)NSString* cardId;
55
+ @property (retain,nonatomic)NSString* cardType;
61
56
  @property (nonatomic, assign) BOOL swiped;
62
- @property (nonatomic, assign) BOOL business;
57
+
63
58
 
64
59
  -(void)leftClickAction;
65
60
  -(void)rightClickAction;
@@ -26,14 +26,10 @@
26
26
  @synthesize delegate;
27
27
 
28
28
  @synthesize panGestureRecognizer;
29
- @synthesize transName;
30
- @synthesize amount;
31
- @synthesize date;
32
- @synthesize category;
33
29
  @synthesize overlayView;
34
30
  @synthesize swiped;
35
- @synthesize business;
36
- @synthesize transactionId;
31
+ @synthesize cardId;
32
+ @synthesize cardType;
37
33
 
38
34
  @synthesize swipeType;
39
35
 
@@ -49,13 +45,10 @@
49
45
  swipeType.textColor = [UIColor blackColor];
50
46
 
51
47
 
52
- // transactionId = [[UILabel alloc]initWithFrame:CGRectMake(0, 170, self.frame.size.width, 100)];
53
- // transactionId.text = @"no info given";
54
-
55
- self.backgroundColor = [UIColor whiteColor];
56
-
57
-
48
+ // cardId = [[UILabel alloc]initWithFrame:CGRectMake(0, 170, self.frame.size.width, 100)];
49
+ // cardId.text = @"no info given";
58
50
 
51
+ // self.backgroundColor = [UIColor whiteColor];
59
52
 
60
53
  panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(beingDragged:)];
61
54
 
@@ -122,9 +115,9 @@
122
115
  // [NSString stringWithFormat: @"X position is: %", xFromCenter];
123
116
 
124
117
  // if (xFromCenter > 30) {
125
- // swipeType.text = @"BUSINESS";
118
+ // swipeType.text = @"RIGHT";
126
119
  // } else if (xFromCenter < -30) {
127
- // swipeType.text = @"PERSONAL";
120
+ // swipeType.text = @"LEFT";
128
121
  // } else {
129
122
  // swipeType.text = @"";
130
123
  // }
@@ -198,7 +191,7 @@
198
191
  -(void)rightAction
199
192
  {
200
193
  CGPoint finishPoint = CGPointMake(500, 2*yFromCenter +self.originalPoint.y);
201
- [UIView animateWithDuration:0.3
194
+ [UIView animateWithDuration:0.1
202
195
  animations:^{
203
196
  self.center = finishPoint;
204
197
  }completion:^(BOOL complete){
@@ -217,7 +210,7 @@
217
210
  -(void)leftAction
218
211
  {
219
212
  CGPoint finishPoint = CGPointMake(-500, 2*yFromCenter +self.originalPoint.y);
220
- [UIView animateWithDuration:0.3
213
+ [UIView animateWithDuration:0.1
221
214
  animations:^{
222
215
  self.center = finishPoint;
223
216
  }completion:^(BOOL complete){
@@ -234,7 +227,7 @@
234
227
  -(void)rightClickAction
235
228
  {
236
229
  CGPoint finishPoint = CGPointMake(600, self.center.y);
237
- [UIView animateWithDuration:0.8
230
+ [UIView animateWithDuration:0.3
238
231
  animations:^{
239
232
  self.center = finishPoint;
240
233
  self.transform = CGAffineTransformMakeRotation(1);
@@ -250,7 +243,7 @@
250
243
  -(void)leftClickAction
251
244
  {
252
245
  CGPoint finishPoint = CGPointMake(-600, self.center.y);
253
- [UIView animateWithDuration:0.8
246
+ [UIView animateWithDuration:0.3
254
247
  animations:^{
255
248
  self.center = finishPoint;
256
249
  self.transform = CGAffineTransformMakeRotation(-1);
@@ -49,4 +49,10 @@
49
49
  @property (nonatomic, assign) int verticalOffset;
50
50
 
51
51
 
52
+ -(void)setCardWithHeight:(NSInteger)height withWidth:(NSInteger)width;
53
+ -(int)loadedCardsCount;
54
+ -(void)removeLoadedCards;
55
+ -(void)removeAllCards;
56
+
57
+
52
58
  @end
@@ -19,7 +19,7 @@
19
19
  }
20
20
  //this makes it so only two cards are loaded at a time to
21
21
  //avoid performance and memory costs
22
- static const int MAX_BUFFER_SIZE = 2; //%%% max number of cards loaded at any given time, must be greater than 1
22
+ static const int MAX_BUFFER_SIZE = 3; //%%% max number of cards loaded at any given time, must be greater than 1
23
23
  static const float CARD_HEIGHT = 310; //%%% height of the draggable card
24
24
  static const float CARD_WIDTH = 300; //%%% width of the draggable card
25
25
 
@@ -38,8 +38,8 @@ static const float CARD_WIDTH = 300; //%%% width of the draggable card
38
38
  self = [super initWithFrame:frame];
39
39
  if (self) {
40
40
  [super layoutSubviews];
41
- [self setupView];
42
- exampleCardLabels = [[NSMutableArray alloc] init]; //%%% placeholder for card-specific information
41
+ // [self setupView];
42
+ // exampleCardLabels = [[NSMutableArray alloc] init]; //%%% placeholder for card-specific information
43
43
  loadedCards = [[NSMutableArray alloc] init];
44
44
  allCards = [[NSMutableArray alloc] init];
45
45
  cardsLoadedIndex = 0;
@@ -47,18 +47,13 @@ static const float CARD_WIDTH = 300; //%%% width of the draggable card
47
47
  // default card dimensions in case they aren't sent
48
48
  cardHeight = 310;
49
49
  cardWidth = 300;
50
- verticalOffset = 20;
50
+ verticalOffset = 30;
51
51
  // [self loadCards];
52
52
  }
53
53
  return self;
54
54
  }
55
55
 
56
- -(void) dummy
57
- {
58
-
59
- }
60
-
61
- -(void) setCardWithHeight:(NSInteger)height withWidth:(NSInteger)width // withOffset:(NSInteger)offset
56
+ -(void)setCardWithHeight:(NSInteger)height withWidth:(NSInteger)width // withOffset:(NSInteger)offset
62
57
  {
63
58
 
64
59
  cardHeight = height;
@@ -91,7 +86,7 @@ static const float CARD_WIDTH = 300; //%%% width of the draggable card
91
86
  -(void)setupView
92
87
  {
93
88
  // #warning customize all of this. These are just place holders to make it look pretty
94
- self.backgroundColor = [UIColor colorWithRed:.92 green:.93 blue:.95 alpha:0.0]; //the gray background colors
89
+ // self.backgroundColor = [UIColor colorWithRed:.92 green:.93 blu`e:.95 alpha:0.0]; //the gray background colors
95
90
  // self.backgroundColor = [UIColor colorWithWhite:myWhiteFloat alpha:myAlphaFloat];
96
91
 
97
92
  // menuButton = [[UIButton alloc]initWithFrame:CGRectMake(17, 34, 22, 15)];
@@ -117,12 +112,12 @@ static const float CARD_WIDTH = 300; //%%% width of the draggable card
117
112
  -(DraggableView *)createDraggableViewWithDataAtIndex:(NSInteger)index
118
113
  {
119
114
  DraggableView *draggableView = [[DraggableView alloc]initWithFrame:CGRectMake((self.frame.size.width - cardWidth)/2, (self.frame.size.height - cardHeight)/2, cardWidth, cardHeight)];
120
- draggableView.transName.text = [allCards objectAtIndex:index]; //%%% placeholder for card-specific information
115
+ // draggableView.transName.text = [allCards objectAtIndex:index]; //%%% placeholder for card-specific information
121
116
  draggableView.delegate = self;
122
117
  return draggableView;
123
118
  }
124
119
 
125
- -(DraggableView *)createDraggableView //WithDataName:(NSString *)transName withAmount:(NSString *)amount withDate:(NSString *)date withCategory:(NSString *)category //withTransaction:(NSString *)transactionId
120
+ -(DraggableView *)createDraggableView //WithDataName:(NSString *)transName withAmount:(NSString *)amount withDate:(NSString *)date withCategory:(NSString *)category //withTransaction:(NSString *)cardId
126
121
  {
127
122
  DraggableView *draggableView = [[DraggableView alloc]initWithFrame:CGRectMake((self.frame.size.width - cardWidth)/2, (verticalOffset), cardWidth, cardHeight)];
128
123
 
@@ -142,7 +137,9 @@ static const float CARD_WIDTH = 300; //%%% width of the draggable card
142
137
  if([allCards count] > 0) {
143
138
  NSInteger numLoadedCardsCap =((([allCards count] > MAX_BUFFER_SIZE) || ([allCards count] == 0))?MAX_BUFFER_SIZE:[allCards count]);
144
139
  //%%% if the buffer size is greater than the data size, there will be an array error, so this makes sure that doesn't happen
145
-
140
+ // NSLog(@"numLoadedCardsCap");
141
+ // NSLog(@"numLoadedCardsCap = %@", numLoadedCardsCap);
142
+ // NSLog(@"numLoadedCardsCap = %i", numLoadedCardsCap);
146
143
  //%%% loops through the exampleCardsLabels array to create a card for each label. This should be customized by removing "allCards" with your own array of data
147
144
  for (int i = 0; i<[allCards count]; i++) {
148
145
  // DraggableView* newCard = [self createDraggableViewWithDataAtIndex:i];
@@ -167,7 +164,7 @@ static const float CARD_WIDTH = 300; //%%% width of the draggable card
167
164
  }
168
165
  DraggableView *c = (DraggableView *) loadedCards[0];
169
166
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
170
- [defaults setObject: c.transactionId forKey:@"currentCard"];
167
+ [defaults setObject: c.cardId forKey:@"cardCurrent"];
171
168
  }
172
169
  return [loadedCards count];
173
170
  }
@@ -192,12 +189,22 @@ static const float CARD_WIDTH = 300; //%%% width of the draggable card
192
189
  [self insertSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-1)] belowSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-2)]];
193
190
  DraggableView *cNew = (DraggableView *) loadedCards[MAX_BUFFER_SIZE-2];
194
191
 
195
- [defaults setObject: cNew.transactionId forKey:@"currentCard"];
192
+ // [defaults setObject: cNew.cardId forKey:@"cardCurrent"];
193
+ // [defaults synchronize];
196
194
  }
195
+ if ([loadedCards count] > 0) {
196
+ DraggableView *temp = (DraggableView *) loadedCards[0];
197
+
198
+ // int card_id = temp.cardId;
199
+ [defaults setObject: temp.cardId forKey:@"cardCurrent"];
200
+ }
201
+
202
+
203
+ [defaults synchronize];
197
204
 
198
205
  // NSLog([NSString stringWithFormat:@"left swipe"]);
199
- [defaults setObject: c.transactionId forKey:@"cardSwiped"];
200
- [defaults setObject:@"personal" forKey:@"cardExpenseType"];
206
+ [defaults setObject:@"left" forKey:@"cardSwipedDirection"];
207
+ [defaults setObject: c.cardId forKey:@"cardSwiped"];
201
208
  [defaults synchronize];
202
209
  }
203
210
 
@@ -211,6 +218,16 @@ static const float CARD_WIDTH = 300; //%%% width of the draggable card
211
218
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
212
219
 
213
220
  [loadedCards removeObjectAtIndex:0]; //%%% card was swiped, so it's no longer a "loaded card"
221
+ // NSLog(@"cardsLoadedIndex is = %i", cardsLoadedIndex);
222
+ // NSLog(@"all cards count is = %i", [allCards count]);
223
+
224
+ // DraggableView *temp = (DraggableView *)loadedCards[1];
225
+ // int card_id = temp.cardId;
226
+
227
+ // NSLog(@"loaded card id = %i", card_id);
228
+
229
+ // [defaults setObject: loadedCards[0].cardId forKey:@"cardCurrent"];
230
+
214
231
 
215
232
  if (cardsLoadedIndex < [allCards count]) { //%%% if we haven't reached the end of all cards, put another into the loaded cards
216
233
  [loadedCards addObject:[allCards objectAtIndex:cardsLoadedIndex]];
@@ -218,14 +235,23 @@ static const float CARD_WIDTH = 300; //%%% width of the draggable card
218
235
  [self insertSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-1)] belowSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-2)]];
219
236
  DraggableView *cNew = (DraggableView *) loadedCards[MAX_BUFFER_SIZE-2];
220
237
 
221
- [defaults setObject: cNew.transactionId forKey:@"currentCard"];
238
+ // [defaults setObject: cNew.cardId forKey:@"cardCurrent"];
239
+
222
240
 
223
241
  }
242
+ if ([loadedCards count] > 0) {
243
+ DraggableView *temp = (DraggableView *) loadedCards[0];
244
+
245
+ // int card_id = temp.cardId;
246
+ [defaults setObject: temp.cardId forKey:@"cardCurrent"];
247
+ }
224
248
 
225
- // NSLog([NSString stringWithFormat:@"right swipe"]);
226
249
 
227
- [defaults setObject:c.transactionId forKey:@"cardSwiped"];
228
- [defaults setObject:@"business" forKey:@"cardExpenseType"];
250
+ [defaults synchronize];
251
+
252
+ // NSLog([NSString stringWithFormat:@"right swipe"]);
253
+ [defaults setObject:@"right" forKey:@"cardSwipedDirection"];
254
+ [defaults setObject:c.cardId forKey:@"cardSwiped"];
229
255
  [defaults synchronize];
230
256
 
231
257
  }
@@ -0,0 +1,3 @@
1
+ #ifdef __OBJC__
2
+ # import <UIKit/UIKit.h>
3
+ #endif
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-swipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Sutevski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Easily create an interface with swipeable cards.
14
14
  email: dameyawn@gmail.com
@@ -19,7 +19,6 @@ files:
19
19
  - README.md
20
20
  - lib/motion-swipe.rb
21
21
  - lib/motion-swipe/motion-swipe.rb
22
- - motion-swipe.gemspec
23
22
  - vendor/motion-swipe/DraggableView.h
24
23
  - vendor/motion-swipe/DraggableView.m
25
24
  - vendor/motion-swipe/DraggableViewBackground.h
@@ -28,8 +27,15 @@ files:
28
27
  - vendor/motion-swipe/OverlayView.m
29
28
  - vendor/motion-swipe/ViewController.h
30
29
  - vendor/motion-swipe/ViewController.m
30
+ - vendor/motion-swipe/build-iPhoneSimulator/DraggableView.m.o
31
+ - vendor/motion-swipe/build-iPhoneSimulator/DraggableViewBackground.m.o
32
+ - vendor/motion-swipe/build-iPhoneSimulator/OverlayView.m.o
33
+ - vendor/motion-swipe/build-iPhoneSimulator/ViewController.m.o
34
+ - vendor/motion-swipe/build-iPhoneSimulator/libmotion-swipe.a
35
+ - vendor/motion-swipe/build-iPhoneSimulator/motion-swipe.pch
31
36
  homepage: http://github.com/dam13n/motion-swipe
32
- licenses: []
37
+ licenses:
38
+ - MIT
33
39
  metadata: {}
34
40
  post_install_message:
35
41
  rdoc_options: []
@@ -1,13 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- Gem::Specification.new do |s|
3
- s.name = "motion-swipe"
4
- s.version = '0.0.4'
5
- s.summary = "Rubymotion gem to use TinderSimpleSwipeCards"
6
- s.description = "Easily create an interface with swipeable cards."
7
- s.authors = ["Damien Sutevski"]
8
- s.email = "dameyawn@gmail.com"
9
- s.homepage = "http://github.com/dam13n/motion-swipe"
10
-
11
- s.require_paths = ["lib", "vendor"]
12
- s.files = `git ls-files`.split($\)
13
- end