Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { StackScreenProps } from '@react-navigation/stack';
import { Image } from 'expo-image';
import * as MediaLibrary from 'expo-media-library';
import React from 'react';
import { ScrollView, StyleSheet, View, Alert } from 'react-native';
import { ScrollView, StyleSheet, View, Alert, Platform } from 'react-native';

import Button from '../../components/Button';
import HeadingText from '../../components/HeadingText';
Expand All @@ -21,20 +21,27 @@ export default class MediaDetailsScreen extends React.Component<Props> {
title: 'MediaLibrary Asset',
};

state = {
state: {
details: MediaLibrary.AssetInfo | null;
detailsWithoutDownloadingFromNetwork: MediaLibrary.AssetInfo | null;
} = {
details: null,
detailsWithoutDownloadingFromNetwork: null,
};

componentDidMount() {
this.getAssetDetails();
}

getAssetDetails = () => {
const { asset } = this.props.route.params;
MediaLibrary.getAssetInfoAsync(asset, { shouldDownloadFromNetwork: false }).then((details) => {
this.setState({ detailsWithoutDownloadingFromNetwork: details });
});
MediaLibrary.getAssetInfoAsync(asset).then((details) => {
this.setState({ details });
});
}
};

goBack() {
const { navigation, route } = this.props;
Expand Down Expand Up @@ -81,6 +88,26 @@ export default class MediaDetailsScreen extends React.Component<Props> {
}
};

addToFavorites = async () => {
const { asset } = this.props.route.params!;

const success = await MediaLibrary.setAssetFavoriteAsync(asset, true);
if (success) {
alert('Asset marked as favorite!');
this.getAssetDetails();
}
};

removeFromFavorites = async () => {
const { asset } = this.props.route.params!;

const success = await MediaLibrary.setAssetFavoriteAsync(asset, false);
if (success) {
alert('Asset removed from favorites!');
this.getAssetDetails();
}
};

renderAsset(asset: MediaLibrary.Asset) {
const aspectRatio = asset.height ? asset.width / asset.height : 1;

Expand Down Expand Up @@ -127,6 +154,15 @@ export default class MediaDetailsScreen extends React.Component<Props> {
</View>
)}

{!album && details && Platform.OS === 'ios' && (
<Button
style={styles.button}
buttonStyle={{ backgroundColor: 'green' }}
title={details.isFavorite ? 'Remove from favorites' : 'Add to favorites'}
onPress={details.isFavorite ? this.removeFromFavorites : this.addToFavorites}
/>
)}

<View style={styles.imageContainer}>{this.renderAsset(asset)}</View>

<HeadingText>Base asset data</HeadingText>
Expand Down
11 changes: 11 additions & 0 deletions apps/test-suite/tests/MediaLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ export async function test(t) {
}
);

if (Platform.OS === 'ios') {
t.it('setAssetFavoriteAsync should mark asset as favorite', async () => {
const favoriteTestAsset = testAssets[0];
const infoBefore = await MediaLibrary.getAssetInfoAsync(favoriteTestAsset);
t.expect(infoBefore.isFavorite).toBe(false);
await MediaLibrary.setAssetFavoriteAsync(favoriteTestAsset, true);
const infoAfter = await MediaLibrary.getAssetInfoAsync(favoriteTestAsset);
t.expect(infoAfter.isFavorite).toBe(true);
});
}

// On both platforms assets should perserve their id. On iOS it's native behaviour,
// but on Android it should be implemented (but it isn't)
// t.it("After createAlbum and addAssetsTo album all assets have the same id", async () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/expo-clipboard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### 🛠 Breaking changes

- Removed deprecated `setString` function. Use `setStringAsync` instead. ([#41758](https://github.com/expo/expo/pull/41758) by [@barthap](https://github.com/barthap))

### 🎉 New features

### 🐛 Bug fixes
Expand Down
8 changes: 0 additions & 8 deletions packages/expo-clipboard/build/Clipboard.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-clipboard/build/Clipboard.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions packages/expo-clipboard/build/Clipboard.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-clipboard/build/Clipboard.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion packages/expo-clipboard/build/ExpoClipboard.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-clipboard/build/ExpoClipboard.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-clipboard/build/ExpoClipboard.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/expo-clipboard/build/web/ClipboardModule.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-clipboard/build/web/ClipboardModule.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 17 additions & 18 deletions packages/expo-clipboard/build/web/ClipboardModule.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading