package expo.modules.image import com.bumptech.glide.RequestBuilder import com.bumptech.glide.request.RequestOptions /** * Conditionally applies the block to the RequestBuilder if the condition is true. */ fun RequestBuilder.customize(`when`: Boolean, block: RequestBuilder.() -> RequestBuilder): RequestBuilder { if (!`when`) { return this } return block() } /** * Conditionally applies the block to the RequestBuilder if the value is not null. */ inline fun RequestBuilder.customize(value: P?, block: RequestBuilder.(P) -> RequestBuilder): RequestBuilder { if (value == null) { return this } return block(value) } /** * Conditionally applies the block to the RequestBuilder if both values aren't null. */ inline fun RequestBuilder.customize(first: P1?, second: P2?, block: RequestBuilder.(P1, P2) -> RequestBuilder): RequestBuilder { if (first == null || second == null) { return this } return block(first, second) } /** * Conditionally applies the block to the RequestOptions if the condition is true. */ inline fun RequestOptions.customize(`when`: Boolean, block: RequestOptions.() -> RequestOptions): RequestOptions { if (!`when`) { return this } return block() } /** * Conditionally applies the block to the RequestOptions if the value is not null. */ inline fun RequestOptions.customize(value: T?, block: RequestOptions.(T) -> RequestOptions): RequestOptions { if (value == null) { return this } return block(value) } fun RequestBuilder.apply(options: RequestOptions?): RequestBuilder { if (options == null) { return this } return apply(options) }