Code Monkey home page Code Monkey logo

imageview's Introduction

Extended Imageview

Currently Titanium.UI.ImageView doesn't support the contentMode property so your rendered image will everytime fit your ImageView. This module allows you to specify which behavior your ImageView must have and adds some extra features to improve the user experience.

Get it

Clone this repository or directly download the latest packaged module version here.

Now, follow these steps to install the packaged version of this module into your application.

Usage

You can easily use this module via Alloy or in a classic way.

Alloy

Here is how you can use the extended-imageview directly in alloy:

<Alloy>
    <Window>
        <View class="container">
            <ImageView module="av.imageview" />
        </View>
    </Window>
</Alloy>

and inside the related TSS you can do

"ImageView": {
    width: 100,
    height: 100,
    image: "https://static.pexels.com/photos/27954/pexels-photo-27954.jpg",
}

Classic

You can instantiate an extended-imageview in this way:

require('av.imageview').createImageView({
    width: 100,
    height: 100,
    image: "https://static.pexels.com/photos/27954/pexels-photo-27954.jpg",
});

API

All Titanium.UI.View properties and methods are supported.

About the enabled contentMode, you can learn more about this here.

Extra properties

Property Description Note
contentMode Set the ImageView content mode Supported contentmodes are listed in a next section.
defaultImage Local image to display when the image download is in progress
brokenLinkImage Local image to display when the given link doesn't work or the image doesn't exists
loadingIndicator Enable or disable the activity indicator when the download is in progress true by default
enableMemoryCache Enable or disable the memory cache mechanism true by default and Android only
clipsToBound More details here (iOS Only)

Extra methods

Method Description Note
setContentMode Set the contentMode property
setLoadingIndicator Set the loadingIndicator property
setDefaultImage Set the defaultImage property
setBrokenLinkImage Set the brokenLinkImage property
setClipsToBound Set the clipToBounds property iOS only
getContentMode Get the value of contentMode property
getLoadingIndicator Get the value of loadingIndicator property
getDefaultImage Get the value of defaultImage property
getBrokenLinkImage Get the value of brokenLinkImage property
getClipsToBound Get the value of clipToBounds property iOS only

Events

Event Description
load Fired when the current image was successfully downloaded
error Fired when the image was not fetched

Supported Content Modes

Here is a list of supported content modes:

Android and iOS

  • CONTENT_MODE_ASPECT_FIT
  • CONTENT_MODE_ASPECT_FILL

iOS only

  • CONTENT_MODE_SCALE_TO_FIT
  • CONTENT_MODE_REDRAW
  • CONTENT_MODE_CENTER
  • CONTENT_MODE_TOP
  • CONTENT_MODE_BOTTOM
  • CONTENT_MODE_LEFT
  • CONTENT_MODE_RIGHT
  • CONTENT_MODE_TOP_LEFT
  • CONTENT_MODE_TOP_RIGHT
  • CONTENT_MODE_BOTTOM_LEFT
  • CONTENT_MODE_BOTTOM_RIGHT

Known issues

Using the Android version inside a ListItemTemplate will cause a rendering problem. To avoid this, set the loadingIndicator property to false as a temporary workaround.

Credits

@mads that with his code inspired me to make this module.

@rs for the amazing SDWebImage library.

@bumptech for the amazing Glide library.

imageview's People

Contributors

andreavitale avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.