Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20567] Hyperloop: Allow class usage with only the framework being required

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2018-04-19T10:45:30.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop, iOS
Labelsframeworks, hyperloop, ios
ReporterHans Knöchel
AssigneeUnknown
Created2016-03-15T12:49:12.000+0000
Updated2018-08-02T22:20:02.000+0000

Description

Currently, when we want to use a UILabel with Hyperloop, we need to require it the following way: *iOS*:
var UILabel = require("UIKit/UILabel");
Now if we want to use another class from the UIKit framework e.g. UIView, we need to do:
var UIView = require("UIKit/UIView");
The approach is to make it possible to require frameworks like we do it in Swift/Objective-C and expose the available classes automatically:
require("UIKit"); // Can we do this require-statement anonymously?

var view = new UIView();
var label = new UILabel();
In addition, Alloy does a similar kind of pre-processing to expose variables like OS_IOS and arguments in new controllers.

Comments

  1. Hans Knöchel 2016-03-15

    /cc [~penrique] & [~jhaynie]
  2. Christopher Williams 2016-03-15

    Something else to consider: What about ES6 module import syntax?
       import { UILabel, UIView } from 'UIKit';
       
  3. Hans Knöchel 2016-03-15

    [~cwilliams] +1, we focus ES6 for 6.0.0. Would need to shift the issue then. Discussions welcome.
  4. Hans Knöchel 2016-04-13

    I just thought of wildcard patterns like
       var view = require("android.view.*")
       
    in Android, but that's not good practice right? Are there API's where package wildcards would make access?
  5. Christopher Williams 2016-04-13

    It's fairly standard practice to use wildcards in java package imports. Most IDEs/tooling automatically expand it out the the actual types you use, so that the wildcard isn't used - probably just to be more specific/improve performance. So I think it would make sense to do an ES6 style import with a wildcard:
       import { View, Gravity } from 'android.view.*';
       import { List, Map } from 'java.util.*';
       
    for ES5 syntax? I guess we'd have to have the require return an object with type names as keys inside it:
       var ViewPackage = require('android.view.*'),
           View = ViewPackage.View,
           Gravity = ViewPackage.Gravity;
       
  6. Christopher Williams 2016-04-13

    BTW, I'd suggest that this ticket be cloned out for the android implementation vs iOS implementation.
  7. Hans Knöchel 2016-04-22

    You are right, that are two different cases. Do we want to put this in 5.4.0 already or 6.0.0?
  8. Hans Knöchel 2018-04-19

    Resolving as Won't Fix since we have ES6 support in Hyperloop 3.1.0 and later already, which can be used for module based import of native frameworks, classes and enums.
  9. Eric Merriman 2018-08-02

    Closing old "Won't fix" tickets. If you disagree, please reopen.

JSON Source