Skip to content

Commit e9319a5

Browse files
authored
Merge pull request #23 from IjzerenHein/feature-android-sharedelementtransitions
feat(android): added support for shared element transitions on ExtendedImageView
2 parents 69990b8 + 8b73104 commit e9319a5

File tree

14 files changed

+126
-374
lines changed

14 files changed

+126
-374
lines changed

.prettierrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true,
6+
"trailingComma": "all",
7+
"useTabs": false,
8+
"overrides": [
9+
{
10+
"files": "*.json",
11+
"options": { "printWidth": 200 }
12+
}
13+
]
14+
}

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"javascript.preferences.quoteStyle": "single",
3-
"editor.formatOnSave": false,
3+
"editor.formatOnSave": true,
44
"java.configuration.updateBuildConfiguration": "disabled"
55
}

README.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
21
# react-native-firebaseui
32

43
## Requirements
4+
55
We assume you already have firebase sdk installed and configured.
66
We're using this great library:
7-
https://github.com/invertase/react-native-firebase
7+
[react-native-firebase](https://github.com/invertase/react-native-firebase)
88

99
## Getting started
1010

@@ -15,15 +15,18 @@ https://github.com/invertase/react-native-firebase
1515
`$ react-native link react-native-firebaseui`
1616

1717
For iOS add the following pod to your podfile:
18-
```
18+
19+
```pod
1920
pod 'SDWebImage', '~> 4.0'
2021
```
22+
2123
and run pod install.
2224

2325
## Android Additional step for PhotoView Library
2426

2527
Add this in your root build.gradle file (usually under `android/build.gradle`):
26-
```
28+
29+
```gradle
2730
allprojects {
2831
repositories {
2932
...
@@ -34,7 +37,6 @@ allprojects {
3437

3538
### Manual installation
3639

37-
3840
#### iOS
3941

4042
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
@@ -45,62 +47,67 @@ allprojects {
4547
#### Android
4648

4749
1. Open up `android/app/src/main/java/[...]/MainApplication.java`
48-
- Add `import io.rumors.reactnativefirebaseui.RNFirebaseUiPackage;` to the imports at the top of the file
49-
- Add `new RNFirebaseUiPackage()` to the list returned by the `getPackages()` method
50+
51+
- Add `import io.rumors.reactnativefirebaseui.RNFirebaseUiPackage;` to the imports at the top of the file
52+
- Add `new RNFirebaseUiPackage()` to the list returned by the `getPackages()` method
53+
5054
2. Append the following lines to `android/settings.gradle`:
51-
```
52-
include ':react-native-firebase-ui'
53-
project(':react-native-firebase-ui').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase-ui/android')
54-
```
55+
56+
```gradle
57+
include ':react-native-firebase-ui'
58+
project(':react-native-firebase-ui').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase-ui/android')
59+
```
60+
5561
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
56-
```
57-
compile project(':react-native-firebase-ui')
58-
```
5962

63+
```gradle
64+
compile project(':react-native-firebase-ui')
65+
```
6066

6167
## Usage
68+
6269
```javascript
63-
import { ImageView, PhotoView } from 'react-native-firebaseui'
70+
import { ImageView, PhotoView } from 'react-native-firebaseui';
6471

6572
//no zoom support
6673
export class MyFirebaseImageView extends Component<void, void, void> {
67-
constructor(props){
68-
super(props)
74+
constructor(props) {
75+
super(props);
6976
}
7077

7178
render() {
72-
let imageProps = this.props
79+
let imageProps = this.props;
7380

7481
return (
7582
<ImageView
7683
{...imageProps}
77-
path='firebase/storage/path'
84+
path="firebase/storage/path"
7885
defaultSource={require('./placeholder.png')} // optional, show placeholder until image is loaded
7986
timestamp={0} //optional, can be used to specify last modified time for same storage path
80-
resizeMode='cover' //'cover', 'contain', 'stretch'
87+
resizeMode="cover" //'cover', 'contain', 'stretch', 'center'
8188
/>
82-
)
89+
);
8390
}
8491
}
8592

8693
//zoom support (android only). On iOS just wrap the ImageView with a scroll view
8794
export class MyFirebasePhotoView extends Component<void, void, void> {
88-
constructor(props){
89-
super(props)
95+
constructor(props) {
96+
super(props);
9097
}
9198

9299
render() {
93-
let imageProps = this.props
100+
let imageProps = this.props;
94101

95102
return (
96103
<PhotoView
97104
{...imageProps}
98-
path='firebase/storage/path'
105+
path="firebase/storage/path"
99106
defaultSource={require('./placeholder.png')} // optional, show placeholder until image is loaded
100107
timestamp={0} //optional, can be used to specify last modified time for same storage path
101-
resizeMode='cover' //'cover', 'contain', 'stretch'
108+
resizeMode="cover" //'cover', 'contain', 'stretch', 'center'
102109
/>
103-
)
110+
);
104111
}
105112
}
106113
```

android/src/main/java/io/rumors/reactnativefirebaseui/storage/ExtendedImageView.java

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,20 @@
11
package io.rumors.reactnativefirebaseui.storage;
22

3-
import java.util.Map;
4-
import java.util.Map.Entry;
5-
import java.util.HashMap;
6-
import java.util.ArrayList;
7-
83
import javax.annotation.Nullable;
94

105
import android.widget.ImageView;
11-
import android.widget.ImageView.ScaleType;
126
import android.graphics.drawable.Drawable;
137

148
import com.facebook.react.uimanager.ThemedReactContext;
159
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
16-
import com.firebase.ui.storage.images.FirebaseImageLoader;
1710
import com.google.firebase.storage.StorageReference;
1811
import com.google.firebase.storage.FirebaseStorage;
1912
import com.bumptech.glide.Glide;
20-
import com.bumptech.glide.load.Transformation;
21-
import com.bumptech.glide.load.resource.bitmap.FitCenter;
22-
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
23-
import com.bumptech.glide.load.MultiTransformation;
2413
import com.bumptech.glide.signature.MediaStoreSignature;
25-
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
26-
27-
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
28-
import jp.wasabeef.glide.transformations.RoundedCornersTransformation.CornerType;
29-
3014

3115
public class ExtendedImageView extends ImageView {
3216
protected String mPath = null;
3317
protected @Nullable Drawable mDefaultImageDrawable;
34-
protected Map<CornerType, Integer> mBorderRadii = new HashMap<CornerType, Integer>();
35-
protected ScaleType mScaleType;
3618
protected long mTimestamp = 0;
3719

3820
protected ThemedReactContext mContext = null;
@@ -54,41 +36,12 @@ public void setTimestamp(long timestamp) {
5436
mTimestamp = timestamp;
5537
}
5638

57-
@Override
58-
public void setScaleType(ScaleType scaleType) {
59-
mScaleType = scaleType;
60-
}
61-
62-
public void setBorderRadius(int borderRadius, CornerType cornerType) {
63-
mBorderRadii.put(cornerType, borderRadius);
64-
}
65-
6639
public void updateView() {
6740
StorageReference storageReference = FirebaseStorage.getInstance().getReference(mPath);
68-
FirebaseImageLoader imageLoader = new FirebaseImageLoader();
69-
70-
ArrayList<Transformation> transformations = new ArrayList<Transformation>(1 + mBorderRadii.size());
71-
72-
if (mScaleType == ScaleType.CENTER_CROP) {
73-
transformations.add(new CenterCrop());
74-
} else {
75-
transformations.add(new FitCenter());
76-
}
77-
78-
for (Entry<CornerType, Integer> entry : mBorderRadii.entrySet()) {
79-
CornerType cornerType = entry.getKey();
80-
Integer radius = entry.getValue();
81-
transformations.add(new RoundedCornersTransformation(radius, 0, cornerType));
82-
}
83-
84-
Transformation[] transformationsArray = transformations.toArray(new Transformation[transformations.size()]);
85-
86-
MultiTransformation multi = new MultiTransformation<>(transformationsArray);
87-
8841
GlideApp.with(mContext)
8942
.load(storageReference)
9043
.placeholder(mDefaultImageDrawable)
91-
.apply(bitmapTransform(multi))
44+
.dontTransform()
9245
//(String mimeType, long dateModified, int orientation)
9346
.signature(new MediaStoreSignature("", mTimestamp, 0))
9447
.into(this);

android/src/main/java/io/rumors/reactnativefirebaseui/storage/FirebaseImageViewManager.java

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
import javax.annotation.Nullable;
44
import android.widget.ImageView.ScaleType;
55

6-
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
7-
86
import com.facebook.react.uimanager.ViewProps;
97
import com.facebook.react.uimanager.annotations.ReactProp;
10-
import com.facebook.react.uimanager.annotations.ReactPropGroup;
118
import com.facebook.react.uimanager.SimpleViewManager;
129
import com.facebook.react.uimanager.ThemedReactContext;
13-
import com.facebook.yoga.YogaConstants;
14-
import com.facebook.react.uimanager.PixelUtil;
15-
import com.facebook.react.uimanager.ThemedReactContext;
1610

1711
public class FirebaseImageViewManager extends SimpleViewManager<ExtendedImageView> {
1812
public static final String REACT_CLASS = "RCTFirebaseImageView";
@@ -49,45 +43,14 @@ public void setResizeMode(ExtendedImageView imageView, @Nullable String resizeMo
4943
scaleType = ScaleType.CENTER_CROP;
5044
} else if ("contain".equals(resizeMode)) {
5145
scaleType = ScaleType.CENTER_INSIDE;
46+
} else if ("stretch".equals(resizeMode)) {
47+
scaleType = ScaleType.FIT_XY;
48+
} else if ("center".equals(resizeMode)) {
49+
scaleType = ScaleType.CENTER;
5250
}
53-
5451
imageView.setScaleType(scaleType);
5552
}
5653

57-
@ReactPropGroup(names = {
58-
ViewProps.BORDER_RADIUS,
59-
ViewProps.BORDER_TOP_LEFT_RADIUS,
60-
ViewProps.BORDER_TOP_RIGHT_RADIUS,
61-
ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
62-
ViewProps.BORDER_BOTTOM_LEFT_RADIUS
63-
}, defaultFloat = YogaConstants.UNDEFINED)
64-
public void setBorderRadius(ExtendedImageView imageView, int index, float borderRadius) {
65-
if (!YogaConstants.isUndefined(borderRadius)) {
66-
borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
67-
}
68-
69-
RoundedCornersTransformation.CornerType cornerType = RoundedCornersTransformation.CornerType.ALL;
70-
switch (index) {
71-
case 0:
72-
cornerType = RoundedCornersTransformation.CornerType.ALL;
73-
break;
74-
case 1:
75-
cornerType = RoundedCornersTransformation.CornerType.TOP_LEFT;
76-
break;
77-
case 2:
78-
cornerType = RoundedCornersTransformation.CornerType.TOP_RIGHT;
79-
break;
80-
case 3:
81-
cornerType = RoundedCornersTransformation.CornerType.BOTTOM_RIGHT;
82-
break;
83-
case 4:
84-
cornerType = RoundedCornersTransformation.CornerType.BOTTOM_LEFT;
85-
break;
86-
}
87-
88-
imageView.setBorderRadius(Math.round(borderRadius), cornerType);
89-
}
90-
9154
@Override
9255
protected void onAfterUpdateTransaction(ExtendedImageView imageView) {
9356
super.onAfterUpdateTransaction(imageView);

android/src/main/java/io/rumors/reactnativefirebaseui/storage/FirebasePhotoViewManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ public void setResizeMode(ExtendedPhotoView imageView, @Nullable String resizeMo
5050
scaleType = ScaleType.CENTER_CROP;
5151
} else if ("contain".equals(resizeMode)) {
5252
scaleType = ScaleType.CENTER_INSIDE;
53+
} else if ("stretch".equals(resizeMode)) {
54+
scaleType = ScaleType.FIT_XY;
55+
} else if ("center".equals(resizeMode)) {
56+
scaleType = ScaleType.CENTER;
5357
}
54-
5558
imageView.setScaleType(scaleType);
5659
}
5760

example/App.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MyFirebaseImageView extends Component {
1717
path="images/firebase_logo.png"
1818
defaultSource={require('./assets/placeholder.png')}
1919
timestamp={1000} //optional, can be used to specify last modified time for same storage path
20-
resizeMode="cover" //'cover', 'contain', 'stretch'
20+
resizeMode="cover" //'cover', 'contain', 'stretch', 'center'
2121
/>
2222
);
2323
}
@@ -34,7 +34,7 @@ class MyFirebasePhotoView extends Component {
3434
path="images/firebase_logo.png"
3535
defaultSource={require('./assets/placeholder.png')}
3636
timestamp={1000} //optional, can be used to specify last modified time for same storage path
37-
resizeMode="cover" //'cover', 'contain', 'stretch'
37+
resizeMode="cover" //'cover', 'contain', 'stretch', 'center'
3838
/>
3939
);
4040
}
@@ -56,9 +56,11 @@ const styles = StyleSheet.create({
5656
flex: 1,
5757
justifyContent: 'center',
5858
alignItems: 'center',
59+
backgroundColor: 'black',
5960
},
6061
image: {
6162
width: 100,
6263
height: 100,
64+
borderRadius: 10,
6365
},
6466
});

0 commit comments

Comments
 (0)