Swiftmessages: Minimum display duration

Created on 2 Feb 2017  路  5Comments  路  Source: SwiftKickMobile/SwiftMessages

Hi there, loving SwiftMessages, implementing it has been a breeze. There's one feature that I would like to set, which is a minimum duration for which the message should show.

I currently am manually running my own timer that subtracts the start time from the current time to ensure that it displays for a minimum amount of time, but this logic should probably be encapsulated within SwiftMessages itself.

The ideal scenario would be if I choose a duration of .forever, it could display for a minimum amount of time, even if .hide() is called.

I envision this could be done one of two ways. Either adding a .minimumDuration property to the SwiftMessages.Config object, or adding a minimumDuration field to the .forever enum case as such: .forever(minimumDuration: TimeInterval).

Would love to get your feedback about this. Thanks again!

All 5 comments

Good to hear it's working for you.

This doesn't seem like a very common use case, but I'll put it on the todo list. I'm super busy at the moment, so I can't say when I'll get to it.

Appreciate it, thanks!

After discussing this further with @huntermonk, I think I get the use case now and it makes a lot of sense. Check out head of master and let me know if this works for you. Here's the documentation:

```swift /** Theunknownoption is similar toforever` in the sense that
the message view will not be automatically hidden. However, it
provides two options that can be useful in some scenarios:

- `delay`: wait the specified time interval before displaying
           the message. If you hide the message during the delay
           interval by calling either `hideAll()` or `hide(id:)`,
           the message will not be displayed. This is not the case for
           `hide()` because it only acts on a visible message. Messages
           shown during another message's delay window are displayed first.
- `minimum`: if the message is displayed, ensure that it is displayed
             for a minimum time interval. If you explicitly hide the
             during this interval, the message will be hidden at the
             end of the interval.

This option is useful for displaying a message when a process is taking
too long but you don't want to display the message if the process completes
in a reasonable amount of time. The value unknown(delay: 0, minimum: 0)
is equivalent to forever.

For example, if a URL load is expected to complete in 2 seconds, you may use
the value unknown(delay: 2, minimum 1) to ensure that the message will not
be displayed in most cases, but will be displayed for at least 1 second if
the operation takes longer than 2 seconds. By specifying a minimum duration,
you can avoid hiding the message too fast if the operation happens to complete
right after the delay.
*/
case unknown(delay: TimeInterval, minimum: TimeInterval)
````

Thanks for looking into it, special credit to @huntermonk for doing my bidding. 馃檪
This looks exactly like what I wanted. My only suggestion would be to maybe change unknown to indefinite, or a similar term, because at least to me, unknown sounds like an error state.

Either way, great work, and its highly appreciated.

Thanks!

Perfect! indefinite it is. I really appreciate the great suggestions. Changes are in 3.2.1.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattem86 picture mattem86  路  4Comments

OsmarMtz picture OsmarMtz  路  7Comments

allaire picture allaire  路  3Comments

H-Ghadirian picture H-Ghadirian  路  6Comments

b992 picture b992  路  4Comments