Skip to content

Commit

Permalink
feat(GiphyContent): add the prop to specify content rating for the se…
Browse files Browse the repository at this point in the history
…arch results

re #58
  • Loading branch information
merlin committed Feb 14, 2022
1 parent 306d44d commit f43a28b
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .release-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ module.exports = {
},
github: {
release: true,
releaseName: '${version}',
releaseName: 'v${version}',
draft: true,
web: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.widget.FrameLayout
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.uimanager.ThemedReactContext
import com.giphy.sdk.core.models.enums.MediaType
import com.giphy.sdk.core.models.enums.RatingType
import com.giphy.sdk.core.models.enums.RenditionType
import com.giphy.sdk.ui.GPHRequestType
import com.giphy.sdk.ui.pagination.GPHContent
Expand Down Expand Up @@ -63,6 +64,8 @@ class GiphyRNGridView @JvmOverloads constructor(
}
}

content.rating = gphRatingByName(value?.getString("rating")) ?: RatingType.pg13;

if (query != null) {
content.searchQuery = query
}
Expand Down Expand Up @@ -108,7 +111,7 @@ class GiphyRNGridView @JvmOverloads constructor(
clipsPreviewRenditionType = renditionByName(value) ?: DEFAULT_RENDITION_TYPE
}

fun setShowCheckeredBackground(value: Boolean?){
fun setShowCheckeredBackground(value: Boolean?) {
gridView.showCheckeredBackground = value ?: false
}
}
17 changes: 12 additions & 5 deletions android/src/main/java/com/giphyreactnativesdk/GiphySettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ fun renditionByName(renditionName: String?): RenditionType? {
}
}

fun gphRatingByName(ratingName: String?): RatingType? {
return when (ratingName) {
null -> null
else -> RatingType.values().firstOrNull {
it.name == ratingName
.replace("-", "")
.lowercase()
} ?: RatingType.unrated
}
}

fun getContentType(contentType: String?): GPHContentType {
return when(contentType) {
null -> GPHContentType.gif
Expand Down Expand Up @@ -73,11 +84,7 @@ fun giphySettingsFromReadableMap(
}

if (options.hasKey(RNSettings.rating.toString())) {
settings.rating = RatingType.values().firstOrNull {
it.name == options.getString(RNSettings.rating.toString())
?.replace("-", "")
?.lowercase()
} ?: RatingType.unrated
settings.rating = gphRatingByName(RNSettings.rating.toString()) ?: RatingType.pg13
}

if (options.hasKey(RNSettings.showConfirmationScreen.toString())) {
Expand Down
39 changes: 36 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ Provides methods to describe a content request to the Giphy API.
| Option | Description | Type | Default | Platform |
| ----------- | -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------- | --------------------------------- |
| mediaType | A media type that should be loaded (e.g. `GiphyMediaType.Gif`) | [`GiphyMediaType`](https://github.com/Giphy/giphy-react-native-sdk/blob/4b0f2d614abb9a7116bdc530e7a39bf52d5424e2/src/native/types.ts#L15-L20) | `.Gif` |&nbsp;Android <br/> ✅&nbsp;iOS |
| rating | Filter query results by specific content rating | [`GiphyRating`](https://github.com/Giphy/giphy-react-native-sdk/blob/5c4586c09acc6ebbc760feecede4b740f55e4d9a/src/native/types.ts#L22-L29) | `.PG13` |&nbsp;Android <br/> ✅&nbsp;iOS |
| searchQuery | A custom search input (e.g. cats) | `string` | `None` |&nbsp;Android <br/> ✅&nbsp;iOS |

### </> trending: `(options: GiphyContentTrendingOptions) => GiphyContentRequest`
Expand All @@ -598,24 +599,56 @@ Provides methods to describe a content request to the Giphy API.
| Option | Description | Type | Default | Platform |
| --------- | -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------- | --------------------------------- |
| mediaType | A media type that should be loaded (e.g. `GiphyMediaType.Gif`) | [`GiphyMediaType`](https://github.com/Giphy/giphy-react-native-sdk/blob/4b0f2d614abb9a7116bdc530e7a39bf52d5424e2/src/native/types.ts#L15-L20) | `.Gif` |&nbsp;Android <br/> ✅&nbsp;iOS |
| rating | Filter query results by specific content rating | [`GiphyRating`](https://github.com/Giphy/giphy-react-native-sdk/blob/5c4586c09acc6ebbc760feecede4b740f55e4d9a/src/native/types.ts#L22-L29) | `.PG13` |&nbsp;Android <br/> ✅&nbsp;iOS |

### </> trendingGifs: `() => GiphyContentRequest`

#### Options

| Option | Description | Type | Default | Platform |
| ------ | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- | --------------------------------- |
| rating | Filter query results by specific content rating | [`GiphyRating`](https://github.com/Giphy/giphy-react-native-sdk/blob/5c4586c09acc6ebbc760feecede4b740f55e4d9a/src/native/types.ts#L22-L29) | `.PG13` |&nbsp;Android <br/> ✅&nbsp;iOS |

### </> trendingStickers: `() => GiphyContentRequest`

#### Options

| Option | Description | Type | Default | Platform |
| ------ | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- | --------------------------------- |
| rating | Filter query results by specific content rating | [`GiphyRating`](https://github.com/Giphy/giphy-react-native-sdk/blob/5c4586c09acc6ebbc760feecede4b740f55e4d9a/src/native/types.ts#L22-L29) | `.PG13` |&nbsp;Android <br/> ✅&nbsp;iOS |

### </> trendingText: `() => GiphyContentRequest`

#### Options

| Option | Description | Type | Default | Platform |
| ------ | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- | --------------------------------- |
| rating | Filter query results by specific content rating | [`GiphyRating`](https://github.com/Giphy/giphy-react-native-sdk/blob/5c4586c09acc6ebbc760feecede4b740f55e4d9a/src/native/types.ts#L22-L29) | `.PG13` |&nbsp;Android <br/> ✅&nbsp;iOS |

### </> recents: `() => GiphyContentRequest`

#### Options

| Option | Description | Type | Default | Platform |
| ------ | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- | --------------------------------- |
| rating | Filter query results by specific content rating | [`GiphyRating`](https://github.com/Giphy/giphy-react-native-sdk/blob/5c4586c09acc6ebbc760feecede4b740f55e4d9a/src/native/types.ts#L22-L29) | `.PG13` |&nbsp;Android <br/> ✅&nbsp;iOS |

### </> emoji: `() => GiphyContentRequest`

#### Options

| Option | Description | Type | Default | Platform |
| ------ | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- | --------------------------------- |
| rating | Filter query results by specific content rating | [`GiphyRating`](https://github.com/Giphy/giphy-react-native-sdk/blob/5c4586c09acc6ebbc760feecede4b740f55e4d9a/src/native/types.ts#L22-L29) | `.PG13` |&nbsp;Android <br/> ✅&nbsp;iOS |

### </> animate: `(options: GiphyContentAnimateOptions) => GiphyContentRequest`

#### Options

| Option | Description | Type | Default | Platform |
| ----------- | --------------------------------- | -------- | ------- | --------------------------------- |
| searchQuery | A custom search input (e.g. cats) | `string` | `None` |&nbsp;Android <br/> ✅&nbsp;iOS |
| Option | Description | Type | Default | Platform |
| ----------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- | --------------------------------- |
| rating | Filter query results by specific content rating | [`GiphyRating`](https://github.com/Giphy/giphy-react-native-sdk/blob/5c4586c09acc6ebbc760feecede4b740f55e4d9a/src/native/types.ts#L22-L29) | `.PG13` |&nbsp;Android <br/> ✅&nbsp;iOS |
| searchQuery | A custom search input (e.g. cats) | `string` | `None` |&nbsp;Android <br/> ✅&nbsp;iOS |

### Example

Expand Down
2 changes: 2 additions & 0 deletions ios/RNGiphyGridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class RNGiphyGridView: UIView, GPHGridDelegate {

//MARK: RN Properties
@objc func setContent(_ value: NSDictionary) -> Void {
let rating = GPHRatingType.fromRNValue(value: value["rating"] as? String)
gridController.rating = rating ?? GPHRatingType.ratedPG13
gridController.content = GPHContent.fromRNValue(value: value)
gridController.update()
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/bump-ios-sdk-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sed \
cd "$PROJECT_ROOT"/example/ios && pod update
yarn --cwd "$PROJECT_ROOT" bootstrap

COMMIT_MSG="build(deps): bump iOS sdk version from $SDK_CURRENT_VERSION to $SDK_LATEST_VERSION"
COMMIT_MSG="build(deps): bump iOS SDK version from $SDK_CURRENT_VERSION to $SDK_LATEST_VERSION"

while true; do
read -rp "Commit \"$COMMIT_MSG\"? " yn
Expand Down
37 changes: 28 additions & 9 deletions src/GiphyContent.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import { GiphyContentRequest, GiphyContentRequestType, GiphyMediaType } from './native/types'
import { GiphyContentRequest, GiphyContentRequestType, GiphyMediaType, GiphyRating } from './native/types'

export type GiphyContentSearchOptions = {
type GiphyContentRating = {
rating?: GiphyRating
}

export type GiphyContentSearchOptions = GiphyContentRating & {
searchQuery: string
mediaType?: GiphyMediaType
}

export type GiphyContentTrendingOptions = {
export type GiphyContentTrendingOptions = GiphyContentRating & {
mediaType?: GiphyMediaType
}

export type GiphyContentAnimateOptions = {
export type GiphyContentTrendingGIFsOptions = GiphyContentRating

export type GiphyContentTrendingStickersOptions = GiphyContentRating

export type GiphyContentTrendingTextOptions = GiphyContentRating

export type GiphyContentRecentsOptions = GiphyContentRating

export type GiphyContentEmojiOptions = GiphyContentRating

export type GiphyContentAnimateOptions = GiphyContentRating & {
searchQuery: string
}

Expand Down Expand Up @@ -38,36 +52,41 @@ export class GiphyContent {
})
}

static trendingGifs(): GiphyContentRequest {
static trendingGifs(options?: GiphyContentTrendingGIFsOptions): GiphyContentRequest {
return makeGiphyContentRequest({
...options,
mediaType: GiphyMediaType.Gif,
requestType: GiphyContentRequestType.Trending,
})
}

static trendingStickers(): GiphyContentRequest {
static trendingStickers(options?: GiphyContentTrendingStickersOptions): GiphyContentRequest {
return makeGiphyContentRequest({
...options,
mediaType: GiphyMediaType.Sticker,
requestType: GiphyContentRequestType.Trending,
})
}

static trendingText(): GiphyContentRequest {
static trendingText(options?: GiphyContentTrendingTextOptions): GiphyContentRequest {
return makeGiphyContentRequest({
...options,
mediaType: GiphyMediaType.Text,
requestType: GiphyContentRequestType.Trending,
})
}

static recents(): GiphyContentRequest {
static recents(options?: GiphyContentRecentsOptions): GiphyContentRequest {
return makeGiphyContentRequest({
...options,
mediaType: GiphyMediaType.Gif,
requestType: GiphyContentRequestType.Recents,
})
}

static emoji(): GiphyContentRequest {
static emoji(options?: GiphyContentEmojiOptions): GiphyContentRequest {
return makeGiphyContentRequest({
...options,
mediaType: GiphyMediaType.Sticker,
requestType: GiphyContentRequestType.Emoji,
})
Expand Down
11 changes: 10 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ export { GiphyVideoView } from './GiphyVideoView'

export { GiphyVideoManager } from './GiphyVideoManager'

export type { GiphyContentSearchOptions, GiphyContentTrendingOptions } from './GiphyContent'
export type {
GiphyContentAnimateOptions,
GiphyContentEmojiOptions,
GiphyContentRecentsOptions,
GiphyContentSearchOptions,
GiphyContentTrendingGIFsOptions,
GiphyContentTrendingOptions,
GiphyContentTrendingStickersOptions,
GiphyContentTrendingTextOptions,
} from './GiphyContent'
export { GiphyContent } from './GiphyContent'

export type { GiphyGridViewProps } from './GiphyGridView'
Expand Down
5 changes: 3 additions & 2 deletions src/native/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export enum GiphyContentRequestType {
}

export type GiphyContentRequest = {
searchQuery: string
requestType: GiphyContentRequestType
mediaType: GiphyMediaType
rating?: GiphyRating
requestType: GiphyContentRequestType
searchQuery: string
}

0 comments on commit f43a28b

Please sign in to comment.