NathanWalker / nativescript-ngx-fonticon

Use custom font icon collections seamlessly with NativeScript + Angular.
MIT License
75 stars 39 forks source link

Icons not working when is not unicode char (ionicons 4) #64

Open Jonatthu opened 4 years ago

Jonatthu commented 4 years ago

if we have a css like this:

.ion-md-sad {
    content: ""
}

The icons will not appear, it is parsing incorrectly.

The fix on the code is this:

TNSFontIconService.prototype.mapCss = function (data) {
        var sets = data.default.split("}");
        var mappedCss = "";
        var cleanValue = function (val) {
            var v = val
                .split("content:")[1]
                .toLowerCase()
                .replace(/\\e/, "\\ue")
                .replace(/\\f/, "\\uf")
                .trim()
                .replace(/\"/g, "")
                .replace(/;/g, "");
            return v;
        };
        for (var _i = 0, sets_1 = sets; _i < sets_1.length; _i++) {
            var set = sets_1[_i];
            var pair = set.replace(/ /g, "").split("{");
            var keyGroups = pair[0];
            var keys = keyGroups.split(",");
            if (pair[1]) {
                var value = cleanValue(pair[1]);
                for (var _a = 0, keys_1 = keys; _a < keys_1.length; _a++) {
                    var key = keys_1[_a];
                    key = key
                        .trim()
                        .slice(1);
                    this.css[this._currentName][key] = value;
                    if (TNSFontIconService_1.debug) {
                        mappedCss += key + ": " + value + "\n";
                    }
                }
            }
        }
        if (TNSFontIconService_1.debug) {
            console.log("mapped css:\n" + mappedCss);
        }
    };

I got to modify the service.js on the node_modules in order to make it work, I do not know @NathanWalker how would you like to extend this plugin in order to support unicode char and this symbols that ionic started using.

Let me know and I can do a pull request if requires.