An open API service indexing awesome lists of open source software.

https://github.com/joetomkinson/xama.jtports.shapedview

Port of ShapeOfView to Xamarin.Android
https://github.com/joetomkinson/xama.jtports.shapedview

android-views androidx animation custom-shape custom-views roundrect shapeofview xamarin xamarin-android

Last synced: 3 months ago
JSON representation

Port of ShapeOfView to Xamarin.Android

Awesome Lists containing this project

README

        

# Xamarin.Android ShapedView
[![platform](https://img.shields.io/badge/platform-Xamarin.Android-purple.svg)](https://www.xamarin.com/)
[![API](https://img.shields.io/badge/API-11%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=11)
[![License: Apache](https://img.shields.io/github/license/DigitalSa1nt/Xama.JTPorts.ShapedView)](https://opensource.org/licenses/Apache-2.0)
[![Nuget](https://img.shields.io/nuget/v/Xama.JTPorts.ShapedView)](https://www.nuget.org/packages/Xama.JTPorts.ShapedView/1.0.1#)

### Namespace: Xama.JTPorts.ShapedView
Port of [ShapeOfView](https://github.com/florent37/ShapeOfView) originally created by [Florent37](https://github.com/florent37)

> Give a custom shape to any android view. Useful for Material Design 2

#### Migrated to use the newer AndroidX Support Libraries
This solution only references AndroidX support libraries, and as such you may need to add this [Nuget Package](https://www.nuget.org/packages/Xamarin.AndroidX.Migration/1.0.4?_src=template) called [Xamarin.AndroidX.Migration](https://github.com/xamarin/XamarinAndroidXMigration) into your Xamarin.Android Solution until you have migrated across fully to AndroidX.

[CREATE SOME SAMPLE GIFS]

# Download
![nugetIcon](https://raw.githubusercontent.com/DigitalSa1nt/Xama.JTPorts.ShapedView/master/nuget/nugetIcon-androidified.png)

Nuget Package: [link](https://www.nuget.org/packages/Xama.JTPorts.ShapedView/1.0.1#)

# Use implemented shapes

ViewShape **disable** the `background` property of your view,
please specify a child with a background to enable it
```xml

```

## RoundRect

[![screen](IMAGE)](LINK)

```xml

```

## ClipCorner

[![screen](IMAGE)](LINK)

```xml

```

## Arc

[![screen](IMAGE)](LINK)

```xml

```

## Diagonal

[![screen](IMAGE)](LINK)

```xml

```

## Triangle

[![screen](IMAGE)](LINK)

```xml

```

## Bubble

[![screen](IMAGE)](LINK)

```xml

```

## Star

[![screen](IMAGE)](LINK)

```xml

```

## Polygon

[![screen](IMAGE)](LINK)

```xml

```

## Dotted Edges with Cut Corners

[![screen](IMAGE)](LINK)

```xml


```

## Animation

All shapes methods can be animated

For example, you can animate a RoundRect corner:

[![screen](gif)](LINK)

```kotlin
ValueAnimator.ofFloat(0f, 200f, 0f).apply {
addUpdateListener { animation -> roundRect.bottomLeftRadius = (animation.animatedValue as Float).toInt() }
duration = 800
repeatCount = ValueAnimator.INFINITE
repeatMode = ValueAnimator.REVERSE
}.start()
```

# Create you own shape

You can use custom shape to cut your view

# Using Drawable (no elevation)

[![screen](IMAGE)](LINK)

```xml


```

# Using Path (with elevation)

This method generates also a **shadow path** (with Lollipop elevation API 21+)

Wrap your view with a `ViewShape`

```xml


```

Then generate a path in your code :

```java
ViewShape ViewShape = findViewById(R.id.myShape)
ViewShape.setClipPathCreator(new ClipPathManager.ClipPathCreator() {
@Override
public Path createClipPath(int width, int height) {
final Path path = new Path();

//eg: triangle
path.moveTo(0, 0);
path.lineTo(0.5 * width, height);
path.lineTo(width, 0);
path.close();

return path;
}
});
```

In some case you have to specify `requiresBitmap = true` to enable ViewShape to draw the shape inside a bitmap before clipping your view. It will be less efficient but can make your custom shape work.

# Contribute

Feel free to fork this project, and add customs shapes just as you would do for the original version.

Please then make a `merge-request` after updated the README with a sample of your shape, including a preview

# Current ToDo

- [ ] Tidy up / Finish this readme.
- [x] Finish port of shapes.
- [x] Create Nuget Package.
- [x] See if we can't Csharp it's implementation a bit more.

# Version History

**1.0.3** - Had to add in old NuGet spec configs for icon and license URL. - Skipped other releases as they were all very much broken.
**1.0.2** - Corrected implementation of clip path creators. fixed breaking bugs.
**1.0.1** - Added/Amended missing nugetspec configurations.
**1.0.0** - First port of ShapeOfView version **1.4.5**

# Credits

Author of ShapeOfView: [Florent Champigny](https://github.com/florent37) - This was ported from his initial Java library.

# Support 💎

If you want to support the work that I do and you find any of these libraries useful? Consider supporting it by joining [**stargazers**](https://github.com/DigitalSa1nt/Xama.JTPorts.ShapedView/stargazers) for this repository. :telescope: :stars:


or alternatively if you want to you can also buy me a coffee.

Buy Me A Coffee
-----
_You know, only if you want to._