Skip to content

Commit

Permalink
refactor: example
Browse files Browse the repository at this point in the history
  • Loading branch information
BANG88 committed Jul 26, 2020
1 parent 23690b5 commit e0c6ed7
Show file tree
Hide file tree
Showing 97 changed files with 9,412 additions and 7,063 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ index.tsx
assets/
tsconfig.json
.vscode
example/
PhotoViewerExample/
docs/
File renamed without changes.
4 changes: 4 additions & 0 deletions PhotoViewerExample/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
};
73 changes: 73 additions & 0 deletions PhotoViewerExample/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

; Ignore polyfills
node_modules/react-native/Libraries/polyfills/.*

; These should not be required directly
; require from fbjs/lib instead: require('fbjs/lib/warning')
node_modules/warning/.*

; Flow doesn't support platforms
.*/Libraries/Utilities/LoadingView.js

[untyped]
.*/node_modules/@react-native-community/cli/.*/.*

[include]

[libs]
node_modules/react-native/interface.js
node_modules/react-native/flow/

[options]
emoji=true

esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable

module.file_ext=.js
module.file_ext=.json
module.file_ext=.ios.js

munge_underscores=true

module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[lints]
sketchy-null-number=warn
sketchy-null-mixed=warn
sketchy-number=warn
untyped-type-import=warn
nonstrict-import=warn
deprecated-type=warn
unsafe-getters-setters=warn
unnecessary-invariant=warn
signature-verification-failure=warn
deprecated-utility=error

[strict]
deprecated-type
nonstrict-import
sketchy-null
unclear-type
unsafe-getters-setters
untyped-import
untyped-type-import

[version]
^0.122.0
File renamed without changes.
16 changes: 11 additions & 5 deletions example/.gitignore → PhotoViewerExample/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
Expand All @@ -40,14 +39,21 @@ yarn-error.log
buck-out/
\.buckd/
*.keystore
!debug.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
# https://docs.fastlane.tools/best-practices/source-control/

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots

# Bundle artifact
*.jsbundle

# CocoaPods
/ios/Pods/
6 changes: 6 additions & 0 deletions PhotoViewerExample/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
};
File renamed without changes.
89 changes: 43 additions & 46 deletions example/photos.js → PhotoViewerExample/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Component } from "react";
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
ScrollView,
Expand All @@ -9,77 +8,76 @@ import {
Image,
TouchableOpacity,
Dimensions,
processColor,
NativeModules,
CameraRoll
} from "react-native";
} from 'react-native';

import PhotoView from "./photo-viewer";
import CameraRoll from '@react-native-community/cameraroll';

const cat = require("./cat-2575694_1920.jpg");
import PhotoView from '@merryjs/photo-viewer';

const cat = require('./cat-2575694_1920.jpg');

const photos = [
{
source: {
uri:
"https://images.pexels.com/photos/45170/kittens-cat-cat-puppy-rush-45170.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb",
'https://images.pexels.com/photos/45170/kittens-cat-cat-puppy-rush-45170.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb',
headers: {
a: "1"
}
a: '1',
},
},
title: "Flash End-of-Life",
title: 'Flash End-of-Life',
summary:
"Adobe announced its roadmap to stop supporting Flash at the end of 2020. ",
'Adobe announced its roadmap to stop supporting Flash at the end of 2020. ',
// must be valid hex color or android will crashes
titleColor: "#f90000",
summaryColor: "green"
titleColor: '#f90000',
summaryColor: 'green',
},
{
source: cat,
title: "Local image"
title: 'Local image',
},

{
source: {
uri:
"https://images.pexels.com/photos/142615/pexels-photo-142615.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"
}
'https://images.pexels.com/photos/142615/pexels-photo-142615.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb',
},
},
{
source: {
uri:
"https://images.pexels.com/photos/82072/cat-82072.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"
}
'https://images.pexels.com/photos/82072/cat-82072.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb',
},
},
{
source: {
uri:
"https://images.pexels.com/photos/248261/pexels-photo-248261.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"
}
'https://images.pexels.com/photos/248261/pexels-photo-248261.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb',
},
},
{
source: {
uri: "https://media.giphy.com/media/3o6vXWzHtGfMR3XoXu/giphy.gif"
uri: 'https://media.giphy.com/media/3o6vXWzHtGfMR3XoXu/giphy.gif',
},
title: "gif 1"
}
title: 'gif 1',
},
];
export default class Photos extends Component {
static navigationOptions = {
title: "Photo Viewer"
title: 'Photo Viewer',
};
state = {
visible: false,
initial: 0,
edges: [],
photos
photos,
};
render() {
const imageSize = Dimensions.get("window").width / 3;
const imageSize = Dimensions.get('window').width / 3;

const imageStyle = {
width: imageSize,
height: imageSize
height: imageSize,
};
return (
<View style={styles.container}>
Expand All @@ -92,10 +90,10 @@ export default class Photos extends Component {
hideShareButton={true}
initial={this.state.initial}
onDismiss={() => {
this.setState({ visible: false });
this.setState({visible: false});
}}
onChange={data => {
this.setState({ initial: data.index });
onChange={(data) => {
this.setState({initial: data.index});
}}
/>
<ScrollView showsVerticalScrollIndicator={false}>
Expand All @@ -104,9 +102,8 @@ export default class Photos extends Component {
<TouchableOpacity
key={index}
style={[imageStyle, {}]}
ref={r => (this.r = r)}
onPress={() => this.setState({ visible: true, initial: index })}
>
ref={(r) => (this.r = r)}
onPress={() => this.setState({visible: true, initial: index})}>
<Image style={imageStyle} source={cat.source} />
</TouchableOpacity>
))}
Expand All @@ -116,17 +113,17 @@ export default class Photos extends Component {
title="Choose Photo "
onPress={() => {
CameraRoll.getPhotos({
first: 10
}).then(res => {
first: 10,
}).then((res) => {
console.log(res);
if (res.edges) {
const edgesUrls = res.edges.map(edge => {
const edgesUrls = res.edges.map((edge) => {
return {
source: edge.node.image
source: edge.node.image,
};
});
console.log(edgesUrls);
this.setState({ photos: this.state.photos.concat(edgesUrls) });
this.setState({photos: this.state.photos.concat(edgesUrls)});
}
});
}}
Expand All @@ -139,16 +136,16 @@ export default class Photos extends Component {
const styles = StyleSheet.create({
container: {
flexGrow: 1,
backgroundColor: "#f5f5f5"
backgroundColor: '#f5f5f5',
},
photoContainer: {
flex: 1,
flexDirection: "row",
flexWrap: "wrap"
flexDirection: 'row',
flexWrap: 'wrap',
},
h1: {
padding: 40,
textAlign: "center",
fontSize: 24
}
textAlign: 'center',
fontSize: 24,
},
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* @format
*/

import 'react-native';
import React from 'react';
import Index from '../index.ios.js';
import App from '../App';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
const tree = renderer.create(
<Index />
);
renderer.create(<App />);
});
18 changes: 4 additions & 14 deletions example/android/app/BUCK → PhotoViewerExample/android/app/_BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@
# - `buck install -r android/app` - compile, install and run application
#

load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")

lib_deps = []

for jarfile in glob(['libs/*.jar']):
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
lib_deps.append(':' + name)
prebuilt_jar(
name = name,
binary_jar = jarfile,
)
create_aar_targets(glob(["libs/*.aar"]))

for aarfile in glob(['libs/*.aar']):
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
lib_deps.append(':' + name)
android_prebuilt_aar(
name = name,
aar = aarfile,
)
create_jar_targets(glob(["libs/*.jar"]))

android_library(
name = "all-libs",
Expand Down
Loading

0 comments on commit e0c6ed7

Please sign in to comment.