-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example of TouchableHighlight and images
- Loading branch information
1 parent
04533e3
commit 2d7942c
Showing
7 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from "react"; | ||
import { | ||
AccessibilityInfo, | ||
Platform, | ||
TouchableHighlight, | ||
Image, | ||
View, | ||
Alert, | ||
ImageSourcePropType, | ||
Dimensions, | ||
} from "react-native"; | ||
import Carousel from "../../src/index"; | ||
import image1 from "../images/1.jpg"; | ||
import image2 from "../images/2.jpg"; | ||
import image3 from "../images/3.jpg"; | ||
|
||
const images: ImageSourcePropType[] = [image1, image2, image3]; | ||
const dimensions = Dimensions.get("window"); | ||
const imageHeight = Math.round((dimensions.width * 9) / 16); | ||
const imageWidth = dimensions.width; | ||
|
||
export const TouchableImages = (): JSX.Element => ( | ||
<Carousel | ||
onIndexChanged={({ index, total }): void => { | ||
if (Platform.OS === "ios") { | ||
const page = index + 1; | ||
AccessibilityInfo.announceForAccessibility( | ||
`Changed to page ${page}/${total}` | ||
); | ||
} | ||
}} | ||
controlsButtonStyle={{ | ||
backgroundColor: "rgba(255, 255, 255, 0.5)", | ||
}} | ||
> | ||
{images.map((image, key) => { | ||
/* eslint-disable react/no-array-index-key */ | ||
return ( | ||
<View | ||
style={{ flex: 1, alignItems: "center", justifyContent: "center" }} | ||
key={key} | ||
> | ||
<TouchableHighlight | ||
accessibilityRole="button" | ||
onPress={(): void => { | ||
Alert.alert(`Image ${key + 1} clicked`); | ||
}} | ||
style={{ | ||
height: imageHeight, | ||
width: imageWidth, | ||
}} | ||
> | ||
<Image | ||
source={image} | ||
style={{ | ||
flex: 1, | ||
height: imageHeight, | ||
width: imageWidth, | ||
}} | ||
/> | ||
</TouchableHighlight> | ||
</View> | ||
); | ||
})} | ||
</Carousel> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "*.jpg"; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.