Skip to content

Commit 5404f3b

Browse files
author
Jeff Haynie
committed
fix webview listener issue and added new test case for webview height auto
1 parent 3b2531e commit 5404f3b

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

demos/KitchenSink/Resources/examples/web_views.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if (Titanium.Platform.name == 'iPhone OS')
2929
// The result for this is going to be centered, because that's where layout puts it.
3030
// But users can make sure that embedded webviews are anchored in the usual way.
3131
data.push({title:'Auto Size', auto:true, hasChild:true, innerHTML:'<html><body style="height:200px;width:100px;border:1px solid #ccc;padding:10px">200 px height, 100 px width.</body></html>'});
32+
data.push({title:'Partial Auto', hasChild:true, partial:true, innerHTML:'<html><body><div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div><hr/><div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div></body></html>'});
3233

3334
// this should work on android too, right?
3435
data.push({title:'HTML5 Video', auto:true, hasChild:true, url:'html5video.html'});
@@ -196,7 +197,13 @@ tableview.addEventListener('click', function(e)
196197
}
197198
});
198199
}
199-
200+
201+
if (rowdata.partial)
202+
{
203+
webview.top = 100;
204+
webview.bottom = 0;
205+
}
206+
200207
w.add(webview);
201208

202209

iphone/Classes/AppModule.m

+18-7
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,26 @@ -(void)dealloc
3535
-(void)addEventListener:(NSArray*)args
3636
{
3737
NSString *type = [args objectAtIndex:0];
38-
KrollCallback* listener = [args objectAtIndex:1];
38+
id listener = [args objectAtIndex:1];
3939

4040
if (appListeners==nil)
4141
{
4242
appListeners = [[NSMutableDictionary alloc] init];
4343
}
4444

45-
listener.type = type;
45+
id<TiEvaluator> context = [self executionContext]==nil ? [self pageContext] : [self executionContext];
46+
ListenerEntry *entry = [[ListenerEntry alloc] initWithListener:listener context:context proxy:self];
47+
48+
49+
if ([listener isKindOfClass:[KrollCallback class]])
50+
{
51+
((KrollCallback*)listener).type = type;
52+
}
53+
else
54+
{
55+
entry.type = type;
56+
}
57+
4658

4759
NSMutableArray *l = [appListeners objectForKey:type];
4860
if (l==nil)
@@ -51,8 +63,6 @@ -(void)addEventListener:(NSArray*)args
5163
[appListeners setObject:l forKey:type];
5264
[l release];
5365
}
54-
id<TiEvaluator> context = [self executionContext]==nil ? [self pageContext] : [self executionContext];
55-
ListenerEntry *entry = [[ListenerEntry alloc] initWithListener:listener context:context proxy:self];
5666
[l addObject:entry];
5767
[entry release];
5868
}
@@ -227,15 +237,16 @@ -(void)willShutdownContext:(NSNotification*)note
227237
{
228238
if ([entry context] == context)
229239
{
230-
[found addObject:[entry listener]];
240+
[found addObject:[NSArray
241+
arrayWithObjects:[entry type],[entry listener],nil]];
231242
}
232243
}
233244
}
234245
if ([found count]>0)
235246
{
236-
for (KrollCallback *callback in found)
247+
for (NSArray *a in found)
237248
{
238-
[self removeEventListener:[NSArray arrayWithObjects:callback.type,callback,nil]];
249+
[self removeEventListener:a];
239250
}
240251
}
241252
}

iphone/Classes/ListenerEntry.h

+3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
id listener;
1414
TiProxy *proxy;
1515
BOOL removed;
16+
NSString *type;
1617
}
18+
@property(nonatomic,readwrite,retain) NSString *type;
19+
1720
-(id)initWithListener:(id)listener_ context:(id<TiEvaluator>)context_ proxy:(TiProxy*)proxy;
1821
-(id<TiEvaluator>)context;
1922
-(id)listener;

iphone/Classes/ListenerEntry.m

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
@implementation ListenerEntry
1111

12+
@synthesize type;
13+
1214
-(id)initWithListener:(id)listener_ context:(id<TiEvaluator>)context_ proxy:(TiProxy*)proxy_
1315
{
1416
if (self = [super init])
@@ -24,6 +26,7 @@ -(id)initWithListener:(id)listener_ context:(id<TiEvaluator>)context_ proxy:(TiP
2426
-(void)dealloc
2527
{
2628
RELEASE_TO_NIL(listener);
29+
RELEASE_TO_NIL(type);
2730
[super dealloc];
2831
}
2932

0 commit comments

Comments
 (0)