@@ -35,10 +35,11 @@ import kotlin.math.min
3535open class ZoomEngine
3636/* *
3737 * Constructs an helper instance.
38+ * The creator has to ensure that [setContainer] is called before any other operation is performed.
3839 *
3940 * @param context a valid context
4041 */
41- internal constructor (context: Context ) : ZoomApi {
42+ constructor (context: Context ) : ZoomApi {
4243
4344 /* *
4445 * Constructs an helper instance.
@@ -351,6 +352,10 @@ internal constructor(context: Context) : ZoomApi {
351352 *
352353 */
353354 fun addListener (listener : Listener ) {
355+ // fail fast if the engine is not initialized properly
356+ if (! ::container.isInitialized) {
357+ error(" container is not initialized." )
358+ }
354359 dispatcher.addListener(listener)
355360 }
356361
@@ -531,11 +536,15 @@ internal constructor(context: Context) : ZoomApi {
531536
532537 /* *
533538 * Set a container to perform transformations on.
534- * This method should only be called once at initialization time.
539+ * This method can only be called once at initialization time. It throws an exception if
540+ * it is called twice.
535541 *
536542 * @param container view
537543 */
538- internal fun setContainer (container : View ) {
544+ fun setContainer (container : View ) {
545+ if (this ::container.isInitialized) {
546+ error(" container already set" )
547+ }
539548 this .container = container
540549 this .container.addOnAttachStateChangeListener(object : View .OnAttachStateChangeListener {
541550 override fun onViewAttachedToWindow (view : View ) {
0 commit comments