Skip to content

Commit

Permalink
fix(ios): fallback to non-widget require in catch
Browse files Browse the repository at this point in the history
This ensures that when the alloy require fails we try the normal require

Fixes TIMOB-27195
  • Loading branch information
ewanharris committed Jul 5, 2019
1 parent 58c26e1 commit 74bfee9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -2897,19 +2897,21 @@ + (TiViewProxy *)unarchiveFromTemplate:(id)viewTemplate_ inContext:(id<TiEvaluat
// 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;"
"var jsModule;"
"try {"
" var jsModule = require('/alloy/widgets/%@/controllers/widget');"
" if (!jsModule) {"
" jsModule = require('/alloy/widgets/%@/controllers/widget');"
"} catch (error) {"
" try {"
" jsModule = require('%@');"
" } catch (e) {"
" Ti.API.error('Failed to load Alloy widget / CommonJS module \"%@\" to be used as template');"
" }"
" if (jsModule) {"
" result = function (parameters) {"
"}"
"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];
Expand Down

0 comments on commit 74bfee9

Please sign in to comment.