jaunesarmiento / fries

Fries helps you prototype Android apps using HTML, CSS, and JavaScript.
MIT License
1.55k stars 222 forks source link

Implement Android Toast notifications #22

Closed jadjoubran closed 10 years ago

jadjoubran commented 11 years ago

Hey

There's this repo that replicates Android Toasts using HTML5 and Javascript ( no jQuery/zepto) dependency. I think it fits well with Fries.

https://github.com/jadjoubran/Android-Toast

jaunesarmiento commented 11 years ago

I'll have a look at it. Thanks bud!

jaunesarmiento commented 11 years ago

Hi @jadjoubran, I noticed two things on your implementation of Toast notifications:

A few things you might want to consider:

Nonetheless, great suggestion. I wasn't really thinking of adding Toast notifications since you can just use the PhoneGap plugin which is implemented natively.

jadjoubran commented 11 years ago

Hi @jaunesarmiento , thanks for taking a look at Android-Toast!

jaunesarmiento commented 11 years ago

Then I guess this can be added to the next release. :)

jadjoubran commented 11 years ago

Hey @jaunesarmiento I updated the repository, kindly check it and let me know what you think!

jaunesarmiento commented 11 years ago

Looks great! :)

aboudard commented 11 years ago

@jadjoubran : Looks nice, fading effect quite close to the original Toast. I see the 5px padding in the box, did you test on different resolutions ? :+1:

jadjoubran commented 11 years ago

@aboudard Does the padding make it look awkward? I tested in Samsung Galaxy S2, S3 & S4 and Nexus 4 Let me know if you have any comments

aboudard commented 11 years ago

@jadjoubran oh no it looks great, I just wonder if the render is not too different on small resolutions and big ones, I'm testing right now :)

jadjoubran commented 11 years ago

@aboudard okay great, let me know. We can fix it using CSS3 media queries to cater for small devices

jadjoubran commented 11 years ago

Hey @jaunesarmiento are you going to include this in your next release? Let me know if I can help in that!

jaunesarmiento commented 11 years ago

Yes, I'll be including this on version 1.0.1. :)

There are a few things I want changed before I include this as a component though:

  1. I'd like this to follow the CamelCase coding style in JavaScript. So Android_Toast should be converted to AndroidToast and methods like set_duration should be setDuration. I want this implemented to provide coding style consistency.
  2. In Fries, CSS classes and ids that have more than one word are separated by a dash -.
  3. And further testing on other devices. :)
aboudard commented 11 years ago

@jadjoubran About the Toast code, I would recommend the use of literal object as parameters, easy to implement and much easer to code with.

in the Class you would find something like that :

function Android_Toast(){

this.timeout_id = null;
this.duration = 3000;
this.content = '';
this.position = 'bottom';
for (var n in arguments[0]) { 
    this[n] = arguments[0][n];
    console.log(arguments[0][n]); // please remove me ;)
}

}

the call would look like that :

var toast = new Android_Toast({content: 'Hello Fries', duration: 5000});

what do you think ?

jaunesarmiento commented 11 years ago

Or the following:

// If we're using fries namespace, do:
// var fries = window.fries || {};
(function () {
  var Toast = function (options) {
    this.init(options);
  }

  Toast.prototype = {
    _defaults: {
      // default options here
    },
    init: function (options) {
      // merge user options with defaults
      // show the Toast
      // then hide Toast after a while
      this.destroy(); // then destroy it
    },
    destroy: function () {
      // destroy Toast here
    }
  };

  // Then expose it in window or Fries namespace
  window.Toast = Toast;
  // or fries.Toast = Toast;
}());
aboudard commented 11 years ago

Even better with the prototype ! I didn't mean to refactor the whole Toast :)

jadjoubran commented 11 years ago

Hey! Thank you for your feedback. However can you please post this as an issue on the project itself? Just decide which one is better and I'll implement it as soon as possible

aboudard commented 11 years ago

@jadjoubran : it's done !

jadjoubran commented 11 years ago

Hey @jaunesarmiento I updated the code and wrapped the JS into an IIFE. Regarding the coding style, shall I do a new branch to provide you the designed coding style? Please advise since it's currently my first contribution to an open source project. Thanks!