-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[7_5_X][TIMOB-26499]: Remove namespace restriction in item templates #10410
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2946,57 +2946,57 @@ - (void)unarchiveFromTemplate:(id)viewTemplate_ | |
+ (TiViewProxy *)unarchiveFromTemplate:(id)viewTemplate_ inContext:(id<TiEvaluator>)context | ||
{ | ||
TiViewTemplate *viewTemplate = [TiViewTemplate templateFromViewTemplate:viewTemplate_]; | ||
if (viewTemplate == nil) { | ||
if (viewTemplate == nil || viewTemplate.type == nil) { | ||
return nil; | ||
} | ||
|
||
if (viewTemplate.type != nil) { | ||
TiViewProxy *proxy = nil; // A proxy can be constructed either | ||
|
||
TiViewProxy *proxy = nil; | ||
@try { | ||
// First try a native proxy class... | ||
if ([viewTemplate.type hasPrefix:@"Ti."] || [viewTemplate.type hasPrefix:@"Titanium."]) { | ||
proxy = (TiViewProxy *)[[self class] createProxy:viewTemplate.type withProperties:nil inContext:context]; | ||
[context.krollContext invokeBlockOnThread:^{ | ||
[context registerProxy:proxy]; | ||
[proxy rememberSelf]; | ||
}]; | ||
proxy = (TiViewProxy *)[[self class] createProxy:viewTemplate.type withProperties:nil inContext:context]; | ||
[context.krollContext invokeBlockOnThread:^{ | ||
[context registerProxy:proxy]; | ||
[proxy rememberSelf]; | ||
}]; | ||
} @catch (NSException *exception) { | ||
// No such class exists, so fall back to trying to load an Alloy widget or CommonJS module | ||
// TODO Cache by name? Otherwise it seems to keep trying to load native class repeatedly (and failing) and has to re-eval this below! | ||
// TODO eval once and pass in the controller name and props as args? | ||
DebugLog(@"[DEBUG] Failed to load native class %@, trying Alloy widget / CommonJS module", viewTemplate.type); | ||
NSString *code = [NSString stringWithFormat:@"var result;" | ||
"try {" | ||
" var jsModule = require('/alloy/widgets/%@/controllers/widget');" | ||
" if (!jsModule) {" | ||
" jsModule = require('%@');" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can see, |
||
" }" | ||
" if (jsModule) {" | ||
" result = function (parameters) {" | ||
" const obj = new jsModule(parameters);" | ||
" return obj.getView();" | ||
" };" | ||
" }" | ||
"} catch (e) {" | ||
" Ti.API.error('Failed to load Alloy widget / CommonJS module \"%@\" to be used as template');" | ||
"}" | ||
"result;", | ||
viewTemplate.type, viewTemplate.type, viewTemplate.type]; | ||
id result = [context evalJSAndWait:code]; | ||
if (result != nil) { | ||
KrollCallback *func = (KrollCallback *)result; | ||
id contructResult = [func call:@[ viewTemplate.properties ] thisObject:nil]; // TODO: Do some error-handling here if the widget contructor fails? | ||
proxy = (TiViewProxy *)contructResult; | ||
} else { | ||
// No such class exists, so fall back to trying to load an Alloy widget or CommonJS module | ||
// TODO Cache by name? Otherwise it seems to keep trying to load native class repeatedly (and failing) and has to re-eval this below! | ||
// TODO eval once and pass in the controller name and props as args? | ||
NSString *code = [NSString stringWithFormat:@"var result;" | ||
"try {" | ||
" var jsModule = require('/alloy/widgets/%@/controllers/widget');" | ||
" if (!jsModule) {" | ||
" jsModule = require('%@');" | ||
" }" | ||
" if (jsModule) {" | ||
" result = function (parameters) {" | ||
" const obj = new jsModule(parameters);" | ||
" return obj.getView();" | ||
" };" | ||
" }" | ||
"} catch (e) {" | ||
" Ti.API.error('Failed to load Alloy widget / CommonJS module \"%@\" to be used as template');" | ||
"}" | ||
"result;", | ||
viewTemplate.type, viewTemplate.type, viewTemplate.type]; | ||
id result = [context evalJSAndWait:code]; | ||
if (result != nil) { | ||
KrollCallback *func = (KrollCallback *)result; | ||
id contructResult = [func call:@[ viewTemplate.properties ] thisObject:nil]; // TODO: Do some error-handling here if the widget contructor fails? | ||
proxy = (TiViewProxy *)contructResult; | ||
} else { | ||
[self throwException:@"Invalid item template type provided" | ||
subreason:@"The item template type provided cannot be resolved." | ||
location:CODELOCATION]; | ||
} | ||
[self throwException:@"Invalid item template type provided" | ||
subreason:@"The item template type provided cannot be resolved." | ||
location:CODELOCATION]; | ||
} | ||
} @finally { | ||
if (proxy != nil) { | ||
[proxy unarchiveFromTemplate:viewTemplate]; | ||
return proxy; | ||
} | ||
} | ||
|
||
return nil; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated, but should this be either:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it should. The first is a relative URL, the second is a legacy-style path that we should eventually not support (as it was treated as either relative or absolute, and I think differed by platform as to which is tried first).
The alloy directory should be a to-level dir under the app's Resources, so the absolute path should be correct to load it.